UNPKG

@selfcommunity/api-services

Version:
103 lines (96 loc) 3.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OnBoardingApiClient = 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 OnBoarding content. */ class OnBoardingApiClient { /** * This endpoint retrieves all onboarding steps. * @param params * @param config */ static getAllSteps(params, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { params, url: Endpoints_1.default.GetAllSteps.url({}), method: Endpoints_1.default.GetAllSteps.method })); } /** * This endpoint retrieves a specific step identified by the step id. * @param step * @param config */ static getAStep(step, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.GetAStep.url({ step }), method: Endpoints_1.default.GetAStep.method })); } /** * This endpoint performs step content generation. * @param step * @param params * @param config */ static startAStep(step, params, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { params, url: Endpoints_1.default.StartAStep.url({ step }), method: Endpoints_1.default.StartAStep.method })); } /** * This endpoint marks a step complete. * @param step * @param config */ static completeAStep(step, config) { return (0, apiRequest_1.apiRequest)(Object.assign(Object.assign({}, config), { url: Endpoints_1.default.CompleteAStep.url({ step }), method: Endpoints_1.default.CompleteAStep.method })); } } exports.OnBoardingApiClient = OnBoardingApiClient; /** * :::tip OnBoarding service can be used in the following way: ```jsx 1. Import the service from our library: import {OnBoardingService} from "@selfcommunity/api-services"; ``` ```jsx 2. Create a function and put the service inside it! The async function `getAStep` will return the paginated list of categories. async getAStep() { return await OnBoardingService.getAStep(); } ``` ```jsx In case of required `params`, just add them inside the brackets. async create(data) { return await OnBoardingService.getAStep(step); } ``` ```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 OnBoardingService { static getAllSteps(params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return OnBoardingApiClient.getAllSteps(params, config); }); } static getAStep(step, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return OnBoardingApiClient.getAStep(step, config); }); } static startAStep(step, params, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return OnBoardingApiClient.startAStep(step, params, config); }); } static completeAStep(step, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return OnBoardingApiClient.completeAStep(step, config); }); } } exports.default = OnBoardingService;