UNPKG

@selfcommunity/api-services

Version:
104 lines (96 loc) 4.76 kB
import { IncubatorCreateParams, IncubatorSearchParams, SCPaginatedResponse } from '../../types'; import { SCIncubatorSubscriptionType, SCIncubatorType, SCUserType } from '@selfcommunity/types'; import { AxiosRequestConfig } from 'axios'; export interface IncubatorApiClientInterface { getAllIncubators(params?: IncubatorSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCIncubatorType>>; searchIncubators(params?: IncubatorSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCIncubatorType>>; getSpecificIncubator(id: number | string, config?: AxiosRequestConfig): Promise<SCIncubatorType>; createIncubator(data: IncubatorCreateParams, config?: AxiosRequestConfig): Promise<SCIncubatorType>; getIncubatorSubscribers(id: number | string, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCUserType>>; subscribeToIncubator(id: number | string, config?: AxiosRequestConfig): Promise<any>; checkIncubatorSubscription(id: number | string, config?: AxiosRequestConfig): Promise<SCIncubatorSubscriptionType>; } /** * Contains all the endpoints needed to manage incubators. */ export declare class IncubatorApiClient { /** * This endpoint retrieves all incubators. * @param params * @param config */ static getAllIncubators(params?: IncubatorSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCIncubatorType>>; /** * This endpoint performs search od Incubators * @param params * @param config */ static searchIncubators(params?: IncubatorSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCIncubatorType>>; /** * This endpoint retrieves a specific incubator. * @param id * @param config */ static getSpecificIncubator(id: number | string, config?: AxiosRequestConfig): Promise<SCIncubatorType>; /** * This endpoint creates an incubator. * @param data * @param config */ static createIncubator(data: IncubatorCreateParams, config?: AxiosRequestConfig): Promise<SCIncubatorType>; /** * This endpoint returns all subscribers of a specific incubator. * @param id * @param config */ static getIncubatorSubscribers(id: number | string, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCUserType>>; /** * This endpoint subscribes to an incubator. * @param id * @param config */ static subscribeToIncubator(id: number | string, config?: AxiosRequestConfig): Promise<any>; /** * This endpoint returns subscribed = true if the incubator (identified in path) is subscribed by the authenticated user. * @param id * @param config */ static checkIncubatorSubscription(id: number | string, config?: AxiosRequestConfig): Promise<SCIncubatorSubscriptionType>; } /** * :::tip Incubator service can be used in the following way: ```jsx 1. Import the service from our library: import {IncubatorService} from "@selfcommunity/api-services"; ``` ```jsx 2. Create a function and put the service inside it! The async function `getAllIncubators` will return the paginated list of incubators. async getAllIncubators() { return await IncubatorService.getAllIncubators(); } ``` ```jsx In case of required `params`, just add them inside the brackets. async getSpecificIncubator(incubatorId) { return await IncubatorService.getSpecificIncubator(incubatorId); } ``` ```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! ``` ::: */ export default class IncubatorService { static getAllIncubators(params?: IncubatorSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCIncubatorType>>; static searchIncubators(params?: IncubatorSearchParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCIncubatorType>>; static getSpecificIncubator(id: number | string, config?: AxiosRequestConfig): Promise<SCIncubatorType>; static createIncubator(data: IncubatorCreateParams, config?: AxiosRequestConfig): Promise<SCIncubatorType>; static getIncubatorSubscribers(id: number | string, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCUserType>>; static subscribeToIncubator(id: number | string, config?: AxiosRequestConfig): Promise<any>; static checkIncubatorSubscription(id: number | string, config?: AxiosRequestConfig): Promise<SCIncubatorSubscriptionType>; }