UNPKG

@selfcommunity/api-services

Version:
110 lines (102 loc) 4.43 kB
import { TagParams, SCPaginatedResponse, TagGetParams } from '../../types'; import { SCTagType } from '@selfcommunity/types'; import { AxiosRequestConfig } from 'axios'; export interface TagApiClientInterface { getAllTags(params?: TagGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCTagType>>; createTag(data: TagParams, config?: AxiosRequestConfig): Promise<SCTagType>; searchUserTags(params?: TagGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCTagType>>; getSpecificTag(id: number | string, config?: AxiosRequestConfig): Promise<SCTagType>; updateTag(id: number | string, data?: TagParams, config?: AxiosRequestConfig): Promise<SCTagType>; patchTag(id: number | string, data?: TagParams, config?: AxiosRequestConfig): Promise<SCTagType>; assignATag(id: number | string, user?: number, category?: number, config?: AxiosRequestConfig): Promise<SCTagType>; } /** * Contains all the endpoints needed to manage tags. * All endpoints require admin role. */ export declare class TagApiClient { /** * This endpoint retrieves all tags. * @param params * @param config */ static getAllTags(params?: TagGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCTagType>>; /** * This endpoint creates a tag * @param data * @param config */ static createTag(data: TagParams, config?: AxiosRequestConfig): Promise<SCTagType>; /** * This endpoint performs tag search. * @param params * @param config */ static searchUserTags(params?: TagGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCTagType>>; /** * This endpoint retrieves a specific tag. * @param id * @param config */ static getSpecificTag(id: number | string, config?: AxiosRequestConfig): Promise<SCTagType>; /** * This endpoint updates a specific tag. * @param id * @param data * @param config */ static updateTag(id: number | string, data?: TagParams, config?: AxiosRequestConfig): Promise<SCTagType>; /** * This endpoint patches a specific tag. * @param id * @param data * @param config */ static patchTag(id: number | string, data?: TagParams, config?: AxiosRequestConfig): Promise<SCTagType>; /** * This endpoint assigns a tag to a user or to a category. * One param between "user" and "category" need to be passed to this endpoint. * @param id * @param user * @param category * @param config */ static assignATag(id: number | string, user?: number, category?: number, config?: AxiosRequestConfig): Promise<SCTagType>; } /** * :::tip Tag service can be used in the following way: ```jsx 1. Import the service from our library: import {TagService} from "@selfcommunity/api-services"; ``` ```jsx 2. Create a function and put the service inside it! The async function `getAllTags` will return the paginated list of tags. async getAllTags() { return await TagService.getAllTags(); } ``` ```jsx In case of required `params`, just add them inside the brackets. async getSpecificTag(tagId) { return await TagService.getSpecificTag(tagId); } ``` ```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 TagService { static getAllTags(params?: TagGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCTagType>>; static createTag(data: TagParams, config?: AxiosRequestConfig): Promise<SCTagType>; static searchUserTags(params?: TagGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCTagType>>; static getSpecificTag(id: number | string, config?: AxiosRequestConfig): Promise<SCTagType>; static updateTag(id: number | string, data?: TagParams, config?: AxiosRequestConfig): Promise<SCTagType>; static patchTag(id: number | string, data?: TagParams, config?: AxiosRequestConfig): Promise<SCTagType>; static assignATag(id: number | string, user?: number, category?: number, config?: AxiosRequestConfig): Promise<SCTagType>; }