UNPKG

@selfcommunity/api-services

Version:
169 lines (161 loc) • 6.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LegalPageApiClient = void 0; const tslib_1 = require("tslib"); const Endpoints_1 = tslib_1.__importDefault(require("../../constants/Endpoints")); const apiRequest_1 = require("../../utils/apiRequest"); const url_1 = require("../../utils/url"); /** * Contains all the endpoints needed to manage legal pages. */ class LegalPageApiClient { /** * This endpoint retrieves all legal pages. * @param params * @param config */ static getLegalPages(params, config) { const p = (0, url_1.urlParams)(params); return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: `${Endpoints_1.default.GetLegalPages.url({})}?${p.toString()}`, method: Endpoints_1.default.GetLegalPages.method })); } /** * This endpoint retrieves a specific legal page. * @param id * @param config */ static getSpecificLegalPage(id, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.LegalPage.url({ id }), method: Endpoints_1.default.LegalPage.method })); } /** * This endpoint retrieves all revisions of a legal page. * @param policy * @param config */ static getAllRevisionsOfLegalPage(policy, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.LegalPageRevisions.url({ policy }), method: Endpoints_1.default.LegalPageRevisions.method })); } /** * This endpoint retrieves all last revisions of legal pages. */ static getAllLastRevisionsOfLegalPages(config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.LegalPagesLastRevision.url({}), method: Endpoints_1.default.LegalPagesLastRevision.method })); } /** * This endpoint retrieves last revision of a legal page. * @param policy * @param config */ static getLastRevisionOfLegalPage(policy, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.LegalPageLastRevision.url({ policy }), method: Endpoints_1.default.LegalPageLastRevision.method })); } /** * This endpoint performs search of a Legal Page. * @param params * @param config */ static searchLegalPages(params, config) { const p = (0, url_1.urlParams)(params); return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: `${Endpoints_1.default.SearchLegalPages.url({})}?${p.toString()}`, method: Endpoints_1.default.SearchLegalPages.method })); } /** * * @param id * @param accept Accept or not accept a legal page, valid values are: ('true', 'on', '1'). * @param config */ static ackLegalPage(id, accept, config) { var _a; return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.AckLegalPage.url({ id }), method: Endpoints_1.default.AckLegalPage.method, data: (_a = { accept: accept }) !== null && _a !== void 0 ? _a : null })); } /** * This endpoint retrieves a specific user ack. * @param id * @param config */ static getSpecificUserAck(id, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.SpecificUserAck.url({ id }), method: Endpoints_1.default.SpecificUserAck.method })); } /** * This endpoint retrieves all user acks. */ static userAckList(config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.UserAckList.url({}), method: Endpoints_1.default.UserAckList.method })); } } exports.LegalPageApiClient = LegalPageApiClient; /** * :::tip LegalPage service can be used in the following way: ```jsx 1. Import the service from our library: import {LegalPageService} from "@selfcommunity/api-services"; ``` ```jsx 2. Create a function and put the service inside it! The async function `getLegalPages` will return the paginated list of legal pages. async getLegalPages() { return await LegalPageService.getLegalPages(); } ``` ```jsx In case of required `params`, just add them inside the brackets. async getSpecificLegalPage(legalPageId) { return await LegalPageService.getSpecificLegalPage(legalPageId); } ``` ```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 LegalPageService { static getLegalPages(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return LegalPageApiClient.getLegalPages(params, config); }); } static getSpecificLegalPage(id, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return LegalPageApiClient.getSpecificLegalPage(id, config); }); } static getAllRevisionsOfLegalPage(policy, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return LegalPageApiClient.getAllRevisionsOfLegalPage(policy, config); }); } static getAllLastRevisionsOfLegalPages(config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return LegalPageApiClient.getAllLastRevisionsOfLegalPages(config); }); } static getLastRevisionOfLegalPage(policy, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return LegalPageApiClient.getLastRevisionOfLegalPage(policy, config); }); } static searchLegalPages(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return LegalPageApiClient.searchLegalPages(params, config); }); } static ackLegalPage(id, accept, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return LegalPageApiClient.ackLegalPage(id, accept, config); }); } static getSpecificUserAck(id, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return LegalPageApiClient.getSpecificUserAck(id, config); }); } static userAckList(config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return LegalPageApiClient.userAckList(config); }); } } exports.default = LegalPageService;