Skip to content

Commit

Permalink
web/satellite: use get project api keys http endpoint
Browse files Browse the repository at this point in the history
This change uses the new /list-paged endpoint in place of the GraphQL query.

Issue:
#6138

Change-Id: I68c35437f3f2e18898783e2fd523cfdfb3f10de3
  • Loading branch information
VitaliiShpital authored and Storj Robot committed Aug 7, 2023
1 parent 256bd18 commit fa4f5a6
Showing 1 changed file with 12 additions and 39 deletions.
51 changes: 12 additions & 39 deletions web/satellite/src/api/accessGrants.ts
Expand Up @@ -27,47 +27,20 @@ export class AccessGrantsApiGql extends BaseGql implements AccessGrantsApi {
* @throws Error
*/
public async get(projectId: string, cursor: AccessGrantCursor): Promise<AccessGrantsPage> {
const query =
`query($projectId: String!, $limit: Int!, $search: String!, $page: Int!, $order: Int!, $orderDirection: Int!) {
project (
publicId: $projectId,
) {
apiKeys (
cursor: {
limit: $limit,
search: $search,
page: $page,
order: $order,
orderDirection: $orderDirection
}
) {
apiKeys {
id,
name,
createdAt
}
search,
limit,
order,
pageCount,
currentPage,
totalCount
}
}
}`;
const path = `${this.ROOT_PATH}/list-paged?projectID=${projectId}&search=${cursor.search}&limit=${cursor.limit}&page=${cursor.page}&order=${cursor.order}&orderDirection=${cursor.orderDirection}`;
const response = await this.client.get(path);

const variables = {
projectId: projectId,
limit: cursor.limit,
search: cursor.search,
page: cursor.page,
order: cursor.order,
orderDirection: cursor.orderDirection,
};
if (!response.ok) {
throw new APIError({
status: response.status,
message: 'Can not get API keys',
requestID: response.headers.get('x-request-id'),
});
}

const response = await this.query(query, variables);
const apiKeys = await response.json();

return this.getAccessGrantsPage(response.data.project.apiKeys);
return this.getAccessGrantsPage(apiKeys);
}

/**
Expand Down Expand Up @@ -214,7 +187,7 @@ export class AccessGrantsApiGql extends BaseGql implements AccessGrantsApi {
* @param page anonymous object from json
*/
private getAccessGrantsPage(page: any): AccessGrantsPage { // eslint-disable-line @typescript-eslint/no-explicit-any
if (!page) {
if (!(page && page.apiKeys)) {
return new AccessGrantsPage();
}

Expand Down

0 comments on commit fa4f5a6

Please sign in to comment.