plane/web/services/project/estimate.service.ts

94 lines
2.5 KiB
TypeScript

// types
import { IEstimate, IEstimateFormData } from "@plane/types";
// helpers
import { API_BASE_URL } from "@/helpers/common.helper";
// services
import { APIService } from "@/services/api.service";
export class EstimateService extends APIService {
constructor() {
super(API_BASE_URL);
}
// fetching the estimates in workspace level
async fetchWorkspaceEstimates(workspaceSlug: string): Promise<IEstimate[] | undefined> {
try {
const { data } = await this.get(`/api/workspaces/${workspaceSlug}/estimates/`);
return data || undefined;
} catch (error) {
throw error;
}
}
async fetchProjectEstimates(workspaceSlug: string, projectId: string): Promise<IEstimate[] | undefined> {
try {
const { data } = await this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/`);
return data || undefined;
} catch (error) {
throw error;
}
}
async fetchEstimateById(
workspaceSlug: string,
projectId: string,
estimateId: string
): Promise<IEstimate | undefined> {
try {
const { data } = await this.get(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/`
);
return data || undefined;
} catch (error) {
throw error;
}
}
async createEstimate(
workspaceSlug: string,
projectId: string,
payload: IEstimateFormData
): Promise<IEstimate | undefined> {
try {
const { data } = await this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/`, payload);
return data || undefined;
} catch (error) {
throw error;
}
}
async updateEstimate(
workspaceSlug: string,
projectId: string,
estimateId: string,
payload: IEstimateFormData
): Promise<IEstimate | undefined> {
try {
const { data } = await this.patch(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/`,
payload
);
return data || undefined;
} catch (error) {
throw error;
}
}
async removeEstimatePoint(
workspaceSlug: string,
projectId: string,
estimateId: string,
estimatePointId: string,
payload: { new_estimate_id: string | undefined }
): Promise<any> {
return this.patch(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/estimate-point/${estimatePointId}/`,
payload
)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}