UNPKG

@selfcommunity/api-services

Version:
264 lines (257 loc) • 10.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CategoryApiClient = void 0; const tslib_1 = require("tslib"); const Endpoints_1 = tslib_1.__importDefault(require("../../constants/Endpoints")); const apiRequest_1 = require("../../utils/apiRequest"); /** * Contains all the endpoints needed to manage categories. */ class CategoryApiClient { /** * This endpoint retrieves all categories. * @param params * @param config */ static getAllCategories(params, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { params, url: Endpoints_1.default.CategoryList.url({}), method: Endpoints_1.default.CategoryList.method })); } /** * This endpoint performs category search. * @param params * @param config */ static searchCategory(params, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { params, url: Endpoints_1.default.SearchCategory.url({}), method: Endpoints_1.default.SearchCategory.method })); } /** * This endpoint creates a category. * @param data * @param config */ static createCategory(data, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.CreateCategory.url({}), method: Endpoints_1.default.CreateCategory.method, data: data }, config)); } /** * This endpoint retrieves a specific category. * @param id * @param config */ static getSpecificCategory(id, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.Category.url({ id }), method: Endpoints_1.default.Category.method }, config)); } /** * This endpoint updates a specific category. * @param id * @param data * @param config */ static updateASpecificCategory(id, data, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.UpdateCategory.url({ id }), method: Endpoints_1.default.UpdateCategory.method, data: data }, config)); } /** * This endpoint patches a specific category. * @param id * @param data * @param config */ static patchASpecificCategory(id, data, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.PatchCategory.url({ id }), method: Endpoints_1.default.PatchCategory.method, data: data }, config)); } /** * This endpoint deletes a specific category identified by ID. * @param id * @param config */ static deleteASpecificCategory(id, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.DeleteCategory.url({ id }), method: Endpoints_1.default.DeleteCategory.method }, config)); } /** * This endpoint returns the audience of a specific category. * @param id * @param config */ static getCategoryAudience(id, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.CategoryAudience.url({ id }), method: Endpoints_1.default.CategoryAudience.method }, config)); } /** * This endpoint returns all followers of a specific category. * @param id * @param params * @param config */ static getCategoryFollowers(id, params, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.CategoryFollowers.url({ id }), method: Endpoints_1.default.CategoryFollowers.method, params }, config)); } /** * This endpoint retrieves the category feed. * @param id * @param params * @param config */ static getCategoryFeed(id, params, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.CategoryFeed.url({ id }), method: Endpoints_1.default.CategoryFeed.method, params }, config)); } /** * This endpoint retrieves the category trending feed. * @param id * @param params * @param config */ static getCategoryTrendingFeed(id, params, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { params, url: Endpoints_1.default.CategoryTrendingFeed.url({ id }), method: Endpoints_1.default.CategoryTrendingFeed.method })); } /** * This endpoint returns all trending followers of a specific category during last n days (default 90) . * @param id * @param params * @param config */ static getCategoryTrendingFollowers(id, params, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.CategoryTrendingPeople.url({ id }), method: Endpoints_1.default.CategoryTrendingPeople.method, params }, config)); } /** * This endpoint follows a category. * @param id * @param config */ static followCategory(id, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.FollowCategory.url({ id }), method: Endpoints_1.default.FollowCategory.method }, config)); } /** * This endpoint returns is_followed = true if the category (identified in path) is followed by the authenticated user. * @param id * @param config */ static checkCategoryIsFollowed(id, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.CheckCategoryIsFollowed.url({ id }), method: Endpoints_1.default.CheckCategoryIsFollowed.method }, config)); } /** * This endpoint retrieves all followed categories by the user. * @param params * @param config */ static getFollowedCategories(params, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { params, url: Endpoints_1.default.CategoriesFollowed.url({}), method: Endpoints_1.default.CategoriesFollowed.method })); } /** * This endpoint retrieves all categories ordered by the number of followers (in descending order). * @param params * @param config */ static getPopularCategories(params, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { params, url: Endpoints_1.default.PopularCategories.url({}), method: Endpoints_1.default.PopularCategories.method })); } } exports.CategoryApiClient = CategoryApiClient; /** * :::tip Category service can be used in the following way: ```jsx 1. Import the service from our library: import {CategoryService} from "@selfcommunity/api-services"; ``` ```jsx 2. Create a function and put the service inside it! The async function `getAllCategories` will return the paginated list of categories. async getAllCategories() { return await CategoryService.getAllCategories(); } ``` ```jsx In case of required `params`, just add them inside the brackets. async getSpecificCategory(categoryId) { return await CategoryService.getSpecificCategory(categoryId); } ``` ```jsx If you need to customize the request, you can add optional config params (`AxiosRequestConfig` type). 1. Declare it(or declare them, it is possible to add multiple params) const headers = headers: {Authorization: `Bearer ${yourToken}`} 2. Add it inside the brackets and pass it to the function, as shown in the previous example! ``` ::: */ class CategoryService { static getAllCategories(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.getAllCategories(params, config); }); } static searchCategory(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.searchCategory(params, config); }); } static createCategory(data, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.createCategory(data, config); }); } static getSpecificCategory(id, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.getSpecificCategory(id, config); }); } static updateASpecificCategory(id, data, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.updateASpecificCategory(id, data, config); }); } static patchASpecificCategory(id, data, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.patchASpecificCategory(id, data, config); }); } static deleteASpecificCategory(id, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.deleteASpecificCategory(id, config); }); } static getCategoryAudience(id, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.getCategoryAudience(id, config); }); } static getCategoryFollowers(id, params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.getCategoryFollowers(id, params, config); }); } static getCategoryFeed(id, params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.getCategoryFeed(id, params, config); }); } static getCategoryTrendingFeed(id, params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.getCategoryTrendingFeed(id, params, config); }); } static getCategoryTrendingFollowers(id, params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.getCategoryTrendingFollowers(id, params, config); }); } static followCategory(id, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.followCategory(id, config); }); } static checkCategoryIsFollowed(id, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.checkCategoryIsFollowed(id, config); }); } static getFollowedCategories(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.getFollowedCategories(params, config); }); } static getPopularCategories(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CategoryApiClient.getPopularCategories(params, config); }); } } exports.default = CategoryService;