UNPKG

@selfcommunity/api-services

Version:
181 lines (174 loc) • 9.44 kB
import { SCCategoryType, SCCategoryAudienceType, SCUserType, SCFeedUnitType, SCCategoryFollowedStatusType } from '@selfcommunity/types'; import { BaseGetParams, CategoryParams, SCPaginatedResponse } from '../../types'; import { AxiosRequestConfig } from 'axios'; export interface CategoryApiClientInterface { getAllCategories(params?: CategoryParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; searchCategory(params?: CategoryParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; createCategory(data: SCCategoryType, config?: AxiosRequestConfig): Promise<SCCategoryType>; getSpecificCategory(id: number | string, config?: AxiosRequestConfig): Promise<SCCategoryType>; updateASpecificCategory(id: number | string, data: SCCategoryType, config?: AxiosRequestConfig): Promise<SCCategoryType>; patchASpecificCategory(id: number | string, data: SCCategoryType, config?: AxiosRequestConfig): Promise<SCCategoryType>; deleteASpecificCategory(id: number | string, config?: AxiosRequestConfig): Promise<any>; getCategoryAudience(id: number | string, config?: AxiosRequestConfig): Promise<SCCategoryAudienceType>; getCategoryFollowers(id: number | string, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCUserType>>; getCategoryFeed(id: number | string, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCFeedUnitType>>; getCategoryTrendingFeed(id: number | string, params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCFeedUnitType>>; getCategoryTrendingFollowers(id: number | string, params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCUserType>>; followCategory(id: number | string, config?: AxiosRequestConfig): Promise<any>; checkCategoryIsFollowed(id: number | string, config?: AxiosRequestConfig): Promise<SCCategoryFollowedStatusType>; getFollowedCategories(params?: CategoryParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; getPopularCategories(params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; } /** * Contains all the endpoints needed to manage categories. */ export declare class CategoryApiClient { /** * This endpoint retrieves all categories. * @param params * @param config */ static getAllCategories(params?: CategoryParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; /** * This endpoint performs category search. * @param params * @param config */ static searchCategory(params?: CategoryParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; /** * This endpoint creates a category. * @param data * @param config */ static createCategory(data: SCCategoryType, config?: AxiosRequestConfig): Promise<SCCategoryType>; /** * This endpoint retrieves a specific category. * @param id * @param config */ static getSpecificCategory(id: number | string, config?: AxiosRequestConfig): Promise<SCCategoryType>; /** * This endpoint updates a specific category. * @param id * @param data * @param config */ static updateASpecificCategory(id: number | string, data: SCCategoryType, config?: AxiosRequestConfig): Promise<SCCategoryType>; /** * This endpoint patches a specific category. * @param id * @param data * @param config */ static patchASpecificCategory(id: number | string, data: SCCategoryType, config?: AxiosRequestConfig): Promise<SCCategoryType>; /** * This endpoint deletes a specific category identified by ID. * @param id * @param config */ static deleteASpecificCategory(id: number | string, config?: AxiosRequestConfig): Promise<any>; /** * This endpoint returns the audience of a specific category. * @param id * @param config */ static getCategoryAudience(id: number | string, config?: AxiosRequestConfig): Promise<SCCategoryAudienceType>; /** * This endpoint returns all followers of a specific category. * @param id * @param params * @param config */ static getCategoryFollowers(id: number | string, params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCUserType>>; /** * This endpoint retrieves the category feed. * @param id * @param params * @param config */ static getCategoryFeed(id: number | string, params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCFeedUnitType>>; /** * This endpoint retrieves the category trending feed. * @param id * @param params * @param config */ static getCategoryTrendingFeed(id: number | string, params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCFeedUnitType>>; /** * This endpoint returns all trending followers of a specific category during last n days (default 90) . * @param id * @param params * @param config */ static getCategoryTrendingFollowers(id: number | string, params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCUserType>>; /** * This endpoint follows a category. * @param id * @param config */ static followCategory(id: number | string, config?: AxiosRequestConfig): Promise<any>; /** * This endpoint returns is_followed = true if the category (identified in path) is followed by the authenticated user. * @param id * @param config */ static checkCategoryIsFollowed(id: number | string, config?: AxiosRequestConfig): Promise<SCCategoryFollowedStatusType>; /** * This endpoint retrieves all followed categories by the user. * @param params * @param config */ static getFollowedCategories(params?: CategoryParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; /** * This endpoint retrieves all categories ordered by the number of followers (in descending order). * @param params * @param config */ static getPopularCategories(params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; } /** * :::tip Category service can be used in the following way: ```jsx 1. Import the service from our library: import {CategoryService} from "@selfcommunity/api-services"; ``` ```jsx 2. Create a function and put the service inside it! The async function `getAllCategories` will return the paginated list of categories. async getAllCategories() { return await CategoryService.getAllCategories(); } ``` ```jsx In case of required `params`, just add them inside the brackets. async getSpecificCategory(categoryId) { return await CategoryService.getSpecificCategory(categoryId); } ``` ```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 CategoryService { static getAllCategories(params?: CategoryParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; static searchCategory(params?: CategoryParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; static createCategory(data: SCCategoryType, config?: AxiosRequestConfig): Promise<SCCategoryType>; static getSpecificCategory(id: number | string, config?: AxiosRequestConfig): Promise<SCCategoryType>; static updateASpecificCategory(id: number | string, data: SCCategoryType, config?: AxiosRequestConfig): Promise<SCCategoryType>; static patchASpecificCategory(id: number | string, data: SCCategoryType, config?: AxiosRequestConfig): Promise<SCCategoryType>; static deleteASpecificCategory(id: number | string, config?: AxiosRequestConfig): Promise<any>; static getCategoryAudience(id: number | string, config?: AxiosRequestConfig): Promise<SCCategoryAudienceType>; static getCategoryFollowers(id: number | string, params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCUserType>>; static getCategoryFeed(id: number | string, params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCFeedUnitType>>; static getCategoryTrendingFeed(id: number | string, params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCFeedUnitType>>; static getCategoryTrendingFollowers(id: number | string, params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCUserType>>; static followCategory(id: number | string, config?: AxiosRequestConfig): Promise<any>; static checkCategoryIsFollowed(id: number | string, config?: AxiosRequestConfig): Promise<SCCategoryFollowedStatusType>; static getFollowedCategories(params?: CategoryParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; static getPopularCategories(params?: BaseGetParams, config?: AxiosRequestConfig): Promise<SCPaginatedResponse<SCCategoryType>>; }