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

128 lines
3.5 KiB
TypeScript
Raw Normal View History

2024-05-23 10:07:25 +00:00
// types
2024-05-27 10:21:27 +00:00
import { IEstimate, IEstimateFormData, IEstimatePoint } from "@plane/types";
2024-05-23 10:07:25 +00:00
// 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);
}
async fetchWorkspaceEstimates(workspaceSlug: string): Promise<IEstimate[] | undefined> {
2024-05-23 10:07:25 +00:00
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> {
2024-05-23 10:07:25 +00:00
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> {
2024-05-23 10:07:25 +00:00
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> {
2024-05-23 10:07:25 +00:00
try {
const { data } = await this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/`, payload);
return data || undefined;
} catch (error) {
throw error;
}
}
async updateEstimate(
2024-05-23 10:07:25 +00:00
workspaceSlug: string,
projectId: string,
estimateId: string,
2024-05-27 11:43:33 +00:00
payload: Partial<IEstimateFormData>
2024-05-28 09:36:22 +00:00
): Promise<{ points: IEstimatePoint[] } | undefined> {
2024-05-23 10:07:25 +00:00
try {
const { data } = await this.patch(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/`,
payload
);
return data || undefined;
} catch (error) {
throw error;
}
}
2024-05-27 10:21:27 +00:00
async createEstimatePoint(
workspaceSlug: string,
projectId: string,
estimateId: string,
payload: Partial<IEstimatePoint>
): Promise<IEstimatePoint | undefined> {
try {
const { data } = await this.post(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/estimate-points/`,
payload
);
return data || undefined;
} catch (error) {
throw error;
}
}
async updateEstimatePoint(
workspaceSlug: string,
projectId: string,
estimateId: string,
estimatePointId: string,
payload: Partial<IEstimatePoint>
): Promise<IEstimatePoint | undefined> {
try {
2024-05-27 11:43:33 +00:00
const { data } = await this.patch(
2024-05-27 10:21:27 +00:00
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/estimate-points/${estimatePointId}/`,
payload
);
return data || undefined;
} catch (error) {
throw error;
}
}
async removeEstimatePoint(
workspaceSlug: string,
projectId: string,
estimateId: string,
estimatePointId: string,
2024-05-27 10:21:27 +00:00
params?: { new_estimate_id: string | undefined }
2024-05-28 11:18:57 +00:00
): Promise<IEstimatePoint[] | undefined> {
2024-05-27 10:21:27 +00:00
return this.delete(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/estimate-points/${estimatePointId}/`,
params
)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
2024-05-23 10:07:25 +00:00
}
}