UNPKG

@selfcommunity/api-services

Version:
92 lines (85 loc) 3.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReactionApiClient = void 0; const tslib_1 = require("tslib"); const apiRequest_1 = require("../../utils/apiRequest"); const Endpoints_1 = tslib_1.__importDefault(require("../../constants/Endpoints")); const url_1 = require("../../utils/url"); /** * Contains all the endpoints needed to manage features. */ class ReactionApiClient { /** * This endpoint retrieves all reactions. * @param params * @param config */ static getAllReactions(params, config) { const p = (0, url_1.urlParams)(params); return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: `${Endpoints_1.default.GetReactions.url({})}?${p.toString()}`, method: Endpoints_1.default.GetReactions.method })); } /** * This endpoint retrieves all reactions data without pagination. * @param params * @param config */ static getAllReactionsList(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const p = (0, url_1.urlParams)(params); const response = yield (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: `${Endpoints_1.default.GetReactions.url({})}?${p.toString()}`, method: Endpoints_1.default.GetReactions.method })); if (response.next) { return response.results.concat(yield ReactionApiClient.getAllReactionsList(params, Object.assign(Object.assign({}, config), { url: response.next, method: Endpoints_1.default.GetReactions.method }))); } return response.results; }); } /** * This endpoint retrieves a specific reaction. * @param id * @param config */ static getSpecificReaction(id, config) { return (0, apiRequest_1.apiRequest)(Object.assign({ url: Endpoints_1.default.GetSpecificReaction.url({ id }), method: Endpoints_1.default.GetSpecificReaction.method }, config)); } } exports.ReactionApiClient = ReactionApiClient; /** * :::tip Feature service can be used in the following way: ```jsx 1. Import the service from our library: import {ReactionService} from "@selfcommunity/api-services"; ``` ```jsx 2. Create a function and put the service inside it! The async function `getAllReactions` will return the list of reactions. async getAllReactions() { return await ReactionService.getAllReactions(); } ``` ```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 ReactionService { static getAllReactions(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return ReactionApiClient.getAllReactions(params, config); }); } static getAllReactionsList(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return ReactionApiClient.getAllReactionsList(params, config); }); } static getSpecificReaction(id, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return ReactionApiClient.getSpecificReaction(id, config); }); } } exports.default = ReactionService;