import { AxiosPromise } from "axios"; import Api from "./Api"; import { ApiResponse } from "./ApiResponses"; import { CreateCommentThreadRequest, CreateCommentRequest, } from "entities/Comments/CommentsInterfaces"; class CommentsApi extends Api { static baseURL = "v1/comments"; static getThreadsAPI = `${CommentsApi.baseURL}/threads`; static getCommentsAPI = CommentsApi.baseURL; static getReactionsAPI = (commentId: string) => `${CommentsApi.getCommentsAPI}/${commentId}/reactions`; static createNewThread( request: CreateCommentThreadRequest, ): AxiosPromise { return Api.post(CommentsApi.getThreadsAPI, request); } static createNewThreadComment( request: CreateCommentRequest, threadId: string, ): AxiosPromise { return Api.post(CommentsApi.getCommentsAPI, request, { threadId, }); } static fetchAppCommentThreads( applicationId: string, ): AxiosPromise { return Api.get(CommentsApi.getThreadsAPI, { applicationId }); } static updateCommentThread( updateCommentThreadRequest: Partial, threadId: string, ): AxiosPromise { return Api.put( `${CommentsApi.getThreadsAPI}/${threadId}`, updateCommentThreadRequest, ); } static updateComment( updateCommentRequest: Partial, commentId: string, ): AxiosPromise { return Api.put( `${CommentsApi.getCommentsAPI}/${commentId}`, updateCommentRequest, ); } static deleteComment(commentId: string): AxiosPromise { return Api.delete(`${CommentsApi.getCommentsAPI}/${commentId}`); } static deleteCommentThread(threadId: string): AxiosPromise { return Api.delete(`${CommentsApi.getThreadsAPI}/${threadId}`); } static addCommentReaction( commentId: string, request: { emoji: string }, ): AxiosPromise { return Api.post(CommentsApi.getReactionsAPI(commentId), request); } static removeCommentReaction( commentId: string, request: { emoji: string }, ): AxiosPromise { return Api.delete(CommentsApi.getReactionsAPI(commentId), null, { data: request, }); } } export default CommentsApi;