import axios, { AxiosInstance } from "axios"; // plane web types import { TGithubEntityConnection } from "@/plane-web/types/integrations"; export class GithubEntityService { protected baseURL: string; private axiosInstance: AxiosInstance; constructor(baseURL: string) { this.baseURL = baseURL; this.axiosInstance = axios.create({ baseURL, withCredentials: true }); } /** * @description fetch entity connections * @param { string } workspaceId * @param { string } workspaceConnectionId * @returns { Promise } */ fetchEntityConnections = async ( workspaceId: string, workspaceConnectionId: string ): Promise => await this.axiosInstance .get(`/api/entity-connections/${workspaceId}/${workspaceConnectionId}`) .then((res) => res.data) .catch((error) => { throw error?.response?.data; }); /** * @description fetch entity connection * @param { string } workspaceId * @param { string } workspaceConnectionId * @param { string } entityId * @returns { Promise } */ fetchEntityConnection = async ( workspaceId: string, workspaceConnectionId: string, entityId: string ): Promise => await this.axiosInstance .get(`/api/entity-connections/${workspaceId}/${workspaceConnectionId}/${entityId}`) .then((res) => res.data) .catch((error) => { throw error?.response?.data; }); /** * @description create entity connection * @param { string } workspaceId * @param { string } workspaceConnectionId * @param { Partial } entityConnection * @returns { Promise } */ createEntityConnection = async ( workspaceId: string, workspaceConnectionId: string, entityConnection: Partial ): Promise => await this.axiosInstance .post(`/api/entity-connections/${workspaceId}/${workspaceConnectionId}`, entityConnection) .then((res) => res.data) .catch((error) => { throw error?.response?.data; }); /** * @description update entity connection * @param { string } workspaceId * @param { string } workspaceConnectionId * @param { string } entityId * @param { Partial } entityConnection * @returns { Promise } */ updateEntityConnection = async ( workspaceId: string, workspaceConnectionId: string, entityId: string, entityConnection: Partial ): Promise => await this.axiosInstance .put(`/api/entity-connections/${workspaceId}/${workspaceConnectionId}/${entityId}`, entityConnection) .then((res) => res.data) .catch((error) => { throw error?.response?.data; }); /** * @description delete entity connection * @param { string } workspaceId * @param { string } workspaceConnectionId * @param { string } entityId * @returns { Promise } */ deleteEntityConnection = async ( workspaceId: string, workspaceConnectionId: string, entityId: string ): Promise => await this.axiosInstance .delete(`/api/entity-connections/${workspaceId}/${workspaceConnectionId}/${entityId}`) .then(() => undefined) .catch((error) => { throw error?.response?.data; }); }