* [WEB-3065] refactor: replace admin services with service packages * chore: minor updates * chore: error handling
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import { API_BASE_URL } from "@plane/constants";
|
|
import { IWorkspaceView, TIssuesResponse } from "@plane/types";
|
|
import { APIService } from "../api.service";
|
|
|
|
export class WorkspaceViewService extends APIService {
|
|
/**
|
|
* Creates an instance of WorkspaceViewService
|
|
* @param {string} baseUrl - The base URL for API requests
|
|
*/
|
|
constructor(BASE_URL?: string) {
|
|
super(BASE_URL || API_BASE_URL);
|
|
}
|
|
|
|
async create(workspaceSlug: string, data: Partial<IWorkspaceView>): Promise<IWorkspaceView> {
|
|
return this.post(`/api/workspaces/${workspaceSlug}/views/`, data)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async update(workspaceSlug: string, viewId: string, data: Partial<IWorkspaceView>): Promise<IWorkspaceView> {
|
|
return this.patch(`/api/workspaces/${workspaceSlug}/views/${viewId}/`, data)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async destroy(workspaceSlug: string, viewId: string): Promise<any> {
|
|
return this.delete(`/api/workspaces/${workspaceSlug}/views/${viewId}/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async list(workspaceSlug: string): Promise<IWorkspaceView[]> {
|
|
return this.get(`/api/workspaces/${workspaceSlug}/views/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async retrieve(workspaceSlug: string, viewId: string): Promise<IWorkspaceView> {
|
|
return this.get(`/api/workspaces/${workspaceSlug}/views/${viewId}/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async getViewIssues(workspaceSlug: string, params: any, config = {}): Promise<TIssuesResponse> {
|
|
return this.get(
|
|
`/api/workspaces/${workspaceSlug}/issues/`,
|
|
{
|
|
params,
|
|
},
|
|
config
|
|
)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
}
|