2023-04-06 09:39:24 +00:00
|
|
|
// services
|
|
|
|
import APIService from "services/api.service";
|
2023-09-20 15:03:25 +00:00
|
|
|
import trackEventServices from "services/track_event.service";
|
2023-04-11 12:24:01 +00:00
|
|
|
// types
|
2023-06-06 16:06:00 +00:00
|
|
|
import type { ICurrentUserResponse, IEstimate, IEstimateFormData } from "types";
|
2023-09-20 15:03:25 +00:00
|
|
|
// helpers
|
2023-09-13 14:51:02 +00:00
|
|
|
import { API_BASE_URL } from "helpers/common.helper";
|
2023-04-06 09:39:24 +00:00
|
|
|
|
2023-09-20 15:03:25 +00:00
|
|
|
export class ProjectEstimateServices extends APIService {
|
2023-04-06 09:39:24 +00:00
|
|
|
constructor() {
|
2023-09-13 14:51:02 +00:00
|
|
|
super(API_BASE_URL);
|
2023-04-06 09:39:24 +00:00
|
|
|
}
|
|
|
|
|
2023-04-21 19:29:57 +00:00
|
|
|
async createEstimate(
|
2023-04-06 09:39:24 +00:00
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
data: IEstimateFormData,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-04-21 19:29:57 +00:00
|
|
|
): Promise<any> {
|
|
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/`, data)
|
2023-05-05 10:15:38 +00:00
|
|
|
.then((response) => {
|
2023-09-14 10:35:31 +00:00
|
|
|
trackEventServices.trackIssueEstimateEvent(response?.data, "ESTIMATE_CREATE", user);
|
2023-05-05 10:15:38 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-04-06 09:39:24 +00:00
|
|
|
.catch((error) => {
|
2023-04-21 19:29:57 +00:00
|
|
|
throw error?.response;
|
2023-04-06 09:39:24 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async patchEstimate(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
estimateId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
data: IEstimateFormData,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-04-06 09:39:24 +00:00
|
|
|
): Promise<any> {
|
2023-09-20 15:03:25 +00:00
|
|
|
return this.patch(`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/`, data)
|
2023-05-05 10:15:38 +00:00
|
|
|
.then((response) => {
|
2023-09-14 10:35:31 +00:00
|
|
|
trackEventServices.trackIssueEstimateEvent(response?.data, "ESTIMATE_UPDATE", user);
|
2023-05-05 10:15:38 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-04-06 09:39:24 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-09-20 15:03:25 +00:00
|
|
|
async getEstimateDetails(workspaceSlug: string, projectId: string, estimateId: string): Promise<IEstimate> {
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/`)
|
2023-04-06 09:39:24 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-21 19:29:57 +00:00
|
|
|
async getEstimatesList(workspaceSlug: string, projectId: string): Promise<IEstimate[]> {
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/`)
|
2023-04-06 09:39:24 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async deleteEstimate(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
estimateId: string,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-09-20 15:03:25 +00:00
|
|
|
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/`)
|
2023-05-05 10:15:38 +00:00
|
|
|
.then((response) => {
|
2023-09-14 10:35:31 +00:00
|
|
|
trackEventServices.trackIssueEstimateEvent(response?.data, "ESTIMATE_DELETE", user);
|
2023-05-05 10:15:38 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-04-06 09:39:24 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new ProjectEstimateServices();
|