import { API_BASE_URL } from "@plane/constants"; import { IAnalyticsResponseV2, TAnalyticsTabsV2Base, TAnalyticsGraphsV2Base } from "@plane/types"; import { APIService } from "./api.service"; export class AnalyticsV2Service extends APIService { constructor() { super(API_BASE_URL); } async getAdvanceAnalytics( workspaceSlug: string, tab: TAnalyticsTabsV2Base, params?: Record, isPeekView?: boolean ): Promise { return this.get( this.processUrl("advance-analytics", workspaceSlug, tab, params, isPeekView), { params: { tab, ...params, }, } ) .then((res) => res?.data) .catch((err) => { throw err?.response?.data; }); } async getAdvanceAnalyticsStats( workspaceSlug: string, tab: Exclude, params?: Record, isPeekView?: boolean ): Promise { const processedUrl = this.processUrl>( "advance-analytics-stats", workspaceSlug, tab, params, isPeekView ); return this.get(processedUrl, { params: { type: tab, ...params, }, }) .then((res) => res?.data) .catch((err) => { throw err?.response?.data; }); } async getAdvanceAnalyticsCharts( workspaceSlug: string, tab: TAnalyticsGraphsV2Base, params?: Record, isPeekView?: boolean ): Promise { const processedUrl = this.processUrl( "advance-analytics-charts", workspaceSlug, tab, params, isPeekView ); return this.get(processedUrl, { params: { type: tab, ...params, }, }) .then((res) => res?.data) .catch((err) => { throw err?.response?.data; }); } processUrl( endpoint: string, workspaceSlug: string, tab: T, params?: Record, isPeekView?: boolean ) { let processedUrl = `/api/workspaces/${workspaceSlug}`; if (isPeekView && tab === "work-items") { const projectId = params?.project_ids.split(",")[0]; processedUrl += `/projects/${projectId}`; } return `${processedUrl}/${endpoint}`; } }