UNPKG

@selfcommunity/api-services

Version:
93 lines (85 loc) 3.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomAdvApiClient = 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 custom advs. */ class CustomAdvApiClient { /** * This endpoint retrieves a specific custom adv. * @param id * @param config */ static getASpecificCustomAdv(id, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.CustomAdv.url({ id }), method: Endpoints_1.default.CustomAdv.method })); } /** * This endpoint retrieves all custom advs. * @param params * @param config */ static getAllCustomAdv(params, config) { const p = (0, url_1.urlParams)(params); return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: `${Endpoints_1.default.CustomAdvList.url({})}?${p.toString()}`, method: Endpoints_1.default.CustomAdvList.method })); } /** * This endpoint performs search of a Custom Adv * @param params * @param config */ static searchCustomAdv(params, config) { const p = (0, url_1.urlParams)(params); return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: `${Endpoints_1.default.CustomAdvSearch.url({})}?${p.toString()}`, method: Endpoints_1.default.CustomAdvSearch.method })); } } exports.CustomAdvApiClient = CustomAdvApiClient; /** * :::tip Custom Adv service can be used in the following way: ```jsx 1. Import the service from our library: import {CustomAdvService} from "@selfcommunity/api-services"; ``` ```jsx 2. Create a function and put the service inside it! The async function `getAllCustomAdv` will return the paginated list of advs. async getAllCustomAdv() { return await CustomAdvService.getAllCustomAdv(); } ``` ```jsx In case of required `params`, just add them inside the brackets. async getASpecificCustomAdv(customAdvId) { return await CustomAdvService.getASpecificCustomAdv(customAdvId); } ``` ```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 CustomAdvService { static getASpecificCustomAdv(id, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CustomAdvApiClient.getASpecificCustomAdv(id, config); }); } static getAllCustomAdv(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CustomAdvApiClient.getAllCustomAdv(params, config); }); } static searchCustomAdv(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return CustomAdvApiClient.searchCustomAdv(params, config); }); } } exports.default = CustomAdvService;