2023-03-15 05:30:05 +00:00
|
|
|
// services
|
|
|
|
import APIService from "services/api.service";
|
2023-04-03 09:34:48 +00:00
|
|
|
import trackEventServices from "services/track-event.service";
|
2023-06-06 16:06:00 +00:00
|
|
|
import { ICurrentUserResponse } from "types";
|
2023-04-03 09:34:48 +00:00
|
|
|
|
2023-03-15 05:30:05 +00:00
|
|
|
// types
|
|
|
|
import { IView } from "types/views";
|
|
|
|
|
2023-09-13 14:51:02 +00:00
|
|
|
import { API_BASE_URL } from "helpers/common.helper";
|
|
|
|
|
2023-03-15 05:30:05 +00:00
|
|
|
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
|
|
|
|
2023-04-03 09:34:48 +00:00
|
|
|
const trackEvent =
|
|
|
|
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";
|
|
|
|
|
2023-03-15 05:30:05 +00:00
|
|
|
class ViewServices extends APIService {
|
|
|
|
constructor() {
|
2023-09-13 14:51:02 +00:00
|
|
|
super(API_BASE_URL);
|
2023-03-15 05:30:05 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async createView(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
data: IView,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-15 05:30:05 +00:00
|
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/`, data)
|
2023-04-03 09:34:48 +00:00
|
|
|
.then((response) => {
|
2023-06-06 16:06:00 +00:00
|
|
|
if (trackEvent) trackEventServices.trackViewEvent(response?.data, "VIEW_CREATE", user);
|
2023-04-03 09:34:48 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-15 05:30:05 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateView(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
viewId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
data: IView,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-15 05:30:05 +00:00
|
|
|
): Promise<any> {
|
|
|
|
return this.put(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/`, data)
|
2023-04-03 09:34:48 +00:00
|
|
|
.then((response) => {
|
2023-06-06 16:06:00 +00:00
|
|
|
if (trackEvent) trackEventServices.trackViewEvent(response?.data, "VIEW_UPDATE", user);
|
2023-04-03 09:34:48 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-15 05:30:05 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async patchView(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
viewId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
data: Partial<IView>,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-15 05:30:05 +00:00
|
|
|
): Promise<any> {
|
|
|
|
return this.patch(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/`,
|
|
|
|
data
|
|
|
|
)
|
2023-04-03 09:34:48 +00:00
|
|
|
.then((response) => {
|
2023-06-06 16:06:00 +00:00
|
|
|
if (trackEvent) trackEventServices.trackViewEvent(response?.data, "VIEW_UPDATE", user);
|
2023-04-03 09:34:48 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-15 05:30:05 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async deleteView(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
viewId: string,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-16 08:37:19 +00:00
|
|
|
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/`)
|
2023-04-03 09:34:48 +00:00
|
|
|
.then((response) => {
|
2023-06-06 16:06:00 +00:00
|
|
|
if (trackEvent) trackEventServices.trackViewEvent(response?.data, "VIEW_DELETE", user);
|
2023-04-03 09:34:48 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-15 05:30:05 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getViews(workspaceSlug: string, projectId: string): Promise<IView[]> {
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/`)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getViewDetails(workspaceSlug: string, projectId: string, viewId: string): Promise<IView> {
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/`)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getViewIssues(workspaceSlug: string, projectId: string, viewId: string): Promise<any> {
|
|
|
|
return this.get(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/issues/`
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-03-28 11:18:46 +00:00
|
|
|
|
|
|
|
async addViewToFavorites(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
data: {
|
|
|
|
view: string;
|
|
|
|
}
|
|
|
|
): Promise<any> {
|
|
|
|
return this.post(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/user-favorite-views/`,
|
|
|
|
data
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async removeViewFromFavorites(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
viewId: string
|
|
|
|
): Promise<any> {
|
|
|
|
return this.delete(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/user-favorite-views/${viewId}/`
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-03-15 05:30:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new ViewServices();
|