From 55b23d2bdb94b2246cb9216002e58e968e3cb9b2 Mon Sep 17 00:00:00 2001 From: Wilfred Asomani Date: Mon, 7 Aug 2023 14:59:45 +0000 Subject: [PATCH] web/satellite: use get owned projects http endpoint This change uses the new /projects/paged endpoint to get user's owned projects in place of the OwnedProjects graphQL query. Issue: https://github.com/storj/storj/issues/6135 Change-Id: I1e8dfdefdc7de51595637577f7d8bdce8e969652 --- web/satellite/src/api/projects.ts | 70 ++++++++++--------------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/web/satellite/src/api/projects.ts b/web/satellite/src/api/projects.ts index 614947038..c11361feb 100644 --- a/web/satellite/src/api/projects.ts +++ b/web/satellite/src/api/projects.ts @@ -73,7 +73,7 @@ export class ProjectsApiGql extends BaseGql implements ProjectsApi { p.description, p.createdAt, p.ownerId, - p.isSelected, + false, p.memberCount, )); } @@ -259,33 +259,30 @@ export class ProjectsApiGql extends BaseGql implements ProjectsApi { * @throws Error */ public async getOwnedProjects(cursor: ProjectsCursor): Promise { - const query = - `query($limit: Int!, $page: Int!) { - ownedProjects( cursor: { limit: $limit, page: $page } ) { - projects { - publicId, - name, - ownerId, - description, - createdAt, - memberCount - }, - limit, - offset, - pageCount, - currentPage, - totalCount - } - }`; + const response = await this.http.get(`${this.ROOT_PATH}/paged?limit=${cursor.limit}&page=${cursor.page}`); - const variables = { - limit: cursor.limit, - page: cursor.page, - }; + if (!response.ok) { + throw new APIError({ + status: response.status, + message: 'Can not get projects', + requestID: response.headers.get('x-request-id'), + }); + } - const response = await this.query(query, variables); + const page = await response.json(); - return this.getProjectsPage(response.data.ownedProjects); + const projects: Project[] = page.projects.map((p: Project) => + new Project( + p.id, + p.name, + p.description, + p.createdAt, + p.ownerId, + false, + p.memberCount, + )); + + return new ProjectsPage(projects, page.limit, page.offset, page.pageCount, page.currentPage, page.totalCount); } /** @@ -334,27 +331,4 @@ export class ProjectsApiGql extends BaseGql implements ProjectsApi { requestID: httpResponse.headers.get('x-request-id'), }); } - - /** - * Method for mapping projects page from json to ProjectsPage type. - * - * @param page anonymous object from json - */ - private getProjectsPage(page: any): ProjectsPage { // eslint-disable-line @typescript-eslint/no-explicit-any - if (!page) { - return new ProjectsPage(); - } - - const projects: Project[] = page.projects.map(key => - new Project( - key.publicId, - key.name, - key.description, - key.createdAt, - key.ownerId, - false, - key.memberCount)); - - return new ProjectsPage(projects, page.limit, page.offset, page.pageCount, page.currentPage, page.totalCount); - } }