chore: workspace view services and fetch keys added

This commit is contained in:
Anmol Singh Bhatia 2023-09-21 15:23:01 +05:30
parent 60ae940d40
commit 6af2aa666a
2 changed files with 65 additions and 1 deletions

View File

@ -12,8 +12,10 @@ const paramsToKey = (params: any) => {
target_date,
sub_issue,
start_target_date,
project,
} = params;
let projectKey = project ? project.split(",") : [];
let stateKey = state ? state.split(",") : [];
let priorityKey = priority ? priority.split(",") : [];
let assigneesKey = assignees ? assignees.split(",") : [];
@ -27,13 +29,14 @@ const paramsToKey = (params: any) => {
const orderBy = params.order_by ? params.order_by.toUpperCase() : "NULL";
// sorting each keys in ascending order
projectKey = projectKey.sort().join("_");
stateKey = stateKey.sort().join("_");
priorityKey = priorityKey.sort().join("_");
assigneesKey = assigneesKey.sort().join("_");
createdByKey = createdByKey.sort().join("_");
labelsKey = labelsKey.sort().join("_");
return `${stateKey}_${priorityKey}_${assigneesKey}_${createdByKey}_${type}_${groupBy}_${orderBy}_${labelsKey}_${startDateKey}_${targetDateKey}_${sub_issue}_${startTargetDate}`;
return `${projectKey}_${stateKey}_${priorityKey}_${assigneesKey}_${createdByKey}_${type}_${groupBy}_${orderBy}_${labelsKey}_${startDateKey}_${targetDateKey}_${sub_issue}_${startTargetDate}`;
};
const inboxParamsToKey = (params: any) => {
@ -149,6 +152,18 @@ export const PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS = (projectId: string, params?
return `PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS${projectId.toUpperCase()}_${paramsKey}`;
};
export const WORKSPACE_VIEWS_LIST = (workspaceSlug: string) =>
`WORKSPACE_VIEWS_LIST_${workspaceSlug.toUpperCase()}`;
export const WORKSPACE_VIEW_DETAILS = (viewId: string) =>
`WORKSPACE_VIEW_DETAILS_${viewId.toUpperCase()}`;
export const WORKSPACE_VIEW_ISSUES = (viewId: string, params: any) => {
if (!params) return `WORKSPACE_VIEW_ISSUES_${viewId.toUpperCase()}`;
const paramsKey = paramsToKey(params);
return `WORKSPACE_VIEW_ISSUES_${viewId.toUpperCase()}_${paramsKey.toUpperCase()}`;
};
export const PROJECT_ISSUES_DETAILS = (issueId: string) =>
`PROJECT_ISSUES_DETAILS_${issueId.toUpperCase()}`;
export const PROJECT_ISSUES_PROPERTIES = (projectId: string) =>

View File

@ -14,6 +14,7 @@ import {
ICurrentUserResponse,
IWorkspaceBulkInviteFormData,
IWorkspaceViewProps,
IView,
} from "types";
class WorkspaceService extends APIService {
@ -261,6 +262,54 @@ class WorkspaceService extends APIService {
throw error?.response?.data;
});
}
async createView(workspaceSlug: string, data: IView): Promise<any> {
return this.post(`/api/workspaces/${workspaceSlug}/views/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async updateView(workspaceSlug: string, viewId: string, data: Partial<IView>): Promise<any> {
return this.patch(`/api/workspaces/${workspaceSlug}/views/${viewId}/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async deleteView(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 getAllViews(workspaceSlug: string): Promise<IView[]> {
return this.get(`/api/workspaces/${workspaceSlug}/views/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getViewDetails(workspaceSlug: string, viewId: string): Promise<IView> {
return this.get(`/api/workspaces/${workspaceSlug}/views/${viewId}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getViewIssues(workspaceSlug: string, params: any): Promise<any> {
return this.get(`/api/workspaces/${workspaceSlug}/issues/`, { params })
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}
export default new WorkspaceService();