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
This commit is contained in:
Wilfred Asomani 2023-08-07 14:59:45 +00:00
parent 34e1caa55a
commit 55b23d2bdb

View File

@ -73,7 +73,7 @@ export class ProjectsApiGql extends BaseGql implements ProjectsApi {
p.description, p.description,
p.createdAt, p.createdAt,
p.ownerId, p.ownerId,
p.isSelected, false,
p.memberCount, p.memberCount,
)); ));
} }
@ -259,33 +259,30 @@ export class ProjectsApiGql extends BaseGql implements ProjectsApi {
* @throws Error * @throws Error
*/ */
public async getOwnedProjects(cursor: ProjectsCursor): Promise<ProjectsPage> { public async getOwnedProjects(cursor: ProjectsCursor): Promise<ProjectsPage> {
const query = const response = await this.http.get(`${this.ROOT_PATH}/paged?limit=${cursor.limit}&page=${cursor.page}`);
`query($limit: Int!, $page: Int!) {
ownedProjects( cursor: { limit: $limit, page: $page } ) {
projects {
publicId,
name,
ownerId,
description,
createdAt,
memberCount
},
limit,
offset,
pageCount,
currentPage,
totalCount
}
}`;
const variables = { if (!response.ok) {
limit: cursor.limit, throw new APIError({
page: cursor.page, 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'), 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);
}
} }