2023-09-13 14:51:02 +00:00
|
|
|
import { API_BASE_URL } from "helpers/common.helper";
|
2023-03-23 05:31:06 +00:00
|
|
|
// services
|
|
|
|
import APIService from "services/api.service";
|
2023-03-30 13:57:46 +00:00
|
|
|
import trackEventServices from "services/track-event.service";
|
2023-03-23 05:31:06 +00:00
|
|
|
// types
|
2023-06-06 16:06:00 +00:00
|
|
|
import { IPage, IPageBlock, RecentPagesResponse, IIssue, ICurrentUserResponse } from "types";
|
2023-03-23 05:31:06 +00:00
|
|
|
|
|
|
|
class PageServices extends APIService {
|
|
|
|
constructor() {
|
2023-09-13 14:51:02 +00:00
|
|
|
super(API_BASE_URL);
|
2023-03-23 05:31:06 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async createPage(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
data: Partial<IPage>,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<IPage> {
|
2023-03-23 05:31:06 +00:00
|
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/`, data)
|
2023-03-30 13:57:46 +00:00
|
|
|
.then((response) => {
|
2023-09-14 10:35:31 +00:00
|
|
|
trackEventServices.trackPageEvent(response?.data, "PAGE_CREATE", user);
|
2023-03-30 13:57:46 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-23 05:31:06 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async patchPage(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
pageId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
data: Partial<IPage>,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-23 05:31:06 +00:00
|
|
|
): Promise<IPage> {
|
|
|
|
return this.patch(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/`,
|
|
|
|
data
|
|
|
|
)
|
2023-03-30 13:57:46 +00:00
|
|
|
.then((response) => {
|
2023-09-14 10:35:31 +00:00
|
|
|
trackEventServices.trackPageEvent(response?.data, "PAGE_UPDATE", user);
|
2023-03-30 13:57:46 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-23 05:31:06 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async deletePage(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
pageId: string,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-23 05:31:06 +00:00
|
|
|
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/`)
|
2023-03-30 13:57:46 +00:00
|
|
|
.then((response) => {
|
2023-09-14 10:35:31 +00:00
|
|
|
trackEventServices.trackPageEvent(response?.data, "PAGE_DELETE", user);
|
2023-03-30 13:57:46 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-23 05:31:06 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async addPageToFavorites(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
data: {
|
|
|
|
page: string;
|
|
|
|
}
|
2023-03-25 18:09:46 +00:00
|
|
|
): Promise<any> {
|
2023-03-23 05:31:06 +00:00
|
|
|
return this.post(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/user-favorite-pages/`,
|
|
|
|
data
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async removePageFromFavorites(workspaceSlug: string, projectId: string, pageId: string) {
|
|
|
|
return this.delete(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/user-favorite-pages/${pageId}`
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-26 10:08:44 +00:00
|
|
|
async getPagesWithParams(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
2023-05-29 13:05:16 +00:00
|
|
|
pageType: "all" | "favorite" | "created_by_me" | "created_by_other"
|
2023-05-26 10:08:44 +00:00
|
|
|
): Promise<IPage[]> {
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/`, {
|
2023-05-29 13:05:16 +00:00
|
|
|
params: {
|
|
|
|
page_view: pageType,
|
|
|
|
},
|
2023-05-26 10:08:44 +00:00
|
|
|
})
|
2023-03-25 18:09:46 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-26 10:08:44 +00:00
|
|
|
async getRecentPages(workspaceSlug: string, projectId: string): Promise<RecentPagesResponse> {
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/`, {
|
|
|
|
params: {
|
|
|
|
page_view: "recent",
|
|
|
|
},
|
|
|
|
})
|
2023-03-25 18:09:46 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getPageDetails(workspaceSlug: string, projectId: string, pageId: string): Promise<IPage> {
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/`)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-23 05:31:06 +00:00
|
|
|
async createPageBlock(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
pageId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
data: Partial<IPageBlock>,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-25 18:09:46 +00:00
|
|
|
): Promise<IPageBlock> {
|
2023-03-23 05:31:06 +00:00
|
|
|
return this.post(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/`,
|
|
|
|
data
|
|
|
|
)
|
2023-03-30 13:57:46 +00:00
|
|
|
.then((response) => {
|
2023-09-14 10:35:31 +00:00
|
|
|
trackEventServices.trackPageBlockEvent(response?.data, "PAGE_BLOCK_CREATE", user);
|
2023-03-30 13:57:46 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-23 05:31:06 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getPageBlock(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
pageId: string,
|
|
|
|
pageBlockId: string
|
|
|
|
): Promise<IPageBlock[]> {
|
|
|
|
return this.get(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/${pageBlockId}/`
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async patchPageBlock(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
pageId: string,
|
|
|
|
pageBlockId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
data: Partial<IPageBlock>,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-23 05:31:06 +00:00
|
|
|
): Promise<IPage> {
|
|
|
|
return this.patch(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/${pageBlockId}/`,
|
|
|
|
data
|
|
|
|
)
|
2023-03-30 13:57:46 +00:00
|
|
|
.then((response) => {
|
2023-09-14 10:35:31 +00:00
|
|
|
trackEventServices.trackPageBlockEvent(response?.data, "PAGE_BLOCK_UPDATE", user);
|
2023-03-30 13:57:46 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-23 05:31:06 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async deletePageBlock(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
pageId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
pageBlockId: string,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-23 05:31:06 +00:00
|
|
|
): Promise<any> {
|
|
|
|
return this.delete(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/${pageBlockId}/`
|
|
|
|
)
|
2023-03-30 13:57:46 +00:00
|
|
|
.then((response) => {
|
2023-09-14 10:35:31 +00:00
|
|
|
trackEventServices.trackPageBlockEvent(response?.data, "PAGE_BLOCK_DELETE", user);
|
2023-03-30 13:57:46 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-23 05:31:06 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async listPageBlocks(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
pageId: string
|
|
|
|
): Promise<IPageBlock[]> {
|
|
|
|
return this.get(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/`
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-03-25 18:09:46 +00:00
|
|
|
|
|
|
|
async convertPageBlockToIssue(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
pageId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
blockId: string,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-25 18:09:46 +00:00
|
|
|
): Promise<IIssue> {
|
|
|
|
return this.post(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/${blockId}/issues/`
|
|
|
|
)
|
2023-03-30 13:57:46 +00:00
|
|
|
.then((response) => {
|
2023-09-14 10:35:31 +00:00
|
|
|
trackEventServices.trackPageBlockEvent(
|
|
|
|
response?.data,
|
|
|
|
"PAGE_BLOCK_CONVERTED_TO_ISSUE",
|
|
|
|
user
|
|
|
|
);
|
2023-03-30 13:57:46 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-25 18:09:46 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-03-23 05:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new PageServices();
|