plane/web/services/view/project_public.service.ts

140 lines
4.2 KiB
TypeScript
Raw Normal View History

2024-01-30 08:56:59 +00:00
import { APIService } from "services/api.service";
// types
import { TView } from "@plane/types";
import { TViewService } from "./types";
// helpers
import { API_BASE_URL } from "helpers/common.helper";
export class ProjectPublicViewService extends APIService implements TViewService {
2024-01-30 08:56:59 +00:00
constructor() {
super(API_BASE_URL);
}
async fetch(workspaceSlug: string, projectId: string | undefined = undefined): Promise<TView[] | undefined> {
if (!projectId) return undefined;
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async fetchById(
workspaceSlug: string,
viewId: string,
projectId: string | undefined = undefined
): Promise<TView | undefined> {
if (!projectId) return undefined;
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async create(
workspaceSlug: string,
data: Partial<TView>,
projectId: string | undefined = undefined
): Promise<TView | undefined> {
if (!projectId) return undefined;
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async update(
workspaceSlug: string,
viewId: string,
data: Partial<TView>,
projectId: string | undefined = undefined
): Promise<TView | undefined> {
if (!projectId) return undefined;
return this.patch(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async remove(
workspaceSlug: string,
viewId: string,
projectId: string | undefined = undefined
): Promise<void | undefined> {
if (!projectId) return undefined;
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async lock(
workspaceSlug: string,
viewId: string,
projectId: string | undefined = undefined
): Promise<TView | undefined> {
if (!projectId) return undefined;
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/lock/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async unlock(
workspaceSlug: string,
viewId: string,
projectId: string | undefined = undefined
): Promise<TView | undefined> {
if (!projectId) return undefined;
2024-02-02 08:22:38 +00:00
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/lock/`)
2024-01-30 08:56:59 +00:00
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async duplicate(
workspaceSlug: string,
viewId: string,
projectId: string | undefined = undefined
): Promise<TView | undefined> {
if (!projectId) return undefined;
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/duplicate/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
2024-01-30 11:15:14 +00:00
async makeFavorite(
workspaceSlug: string,
viewId: string,
projectId: string | undefined = undefined
): Promise<TView | undefined> {
if (!projectId) return undefined;
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/favorite/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
async removeFavorite(
workspaceSlug: string,
viewId: string,
projectId: string | undefined = undefined
): Promise<TView | undefined> {
if (!projectId) return undefined;
2024-02-02 08:22:38 +00:00
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/favorite/`)
2024-01-30 11:15:14 +00:00
.then((response) => response?.data)
.catch((error) => {
throw error?.response;
});
}
2024-01-30 08:56:59 +00:00
}