Skip to content

Commit

Permalink
client batch check - update response to have result not responses
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyjames committed Jan 10, 2025
1 parent 5316b0f commit 8d32ee2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions config/clients/js/template/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export type ClientBatchCheckSingleClientResponse = {
});

export interface ClientBatchCheckClientResponse {
responses: ClientBatchCheckSingleClientResponse[];
result: ClientBatchCheckSingleClientResponse[];
}

export interface ClientBatchCheckClientRequestOpts {
Expand Down Expand Up @@ -632,7 +632,7 @@ export class {{appShortName}}Client extends BaseAPI {
setHeaderIfNotSet(headers, CLIENT_METHOD_HEADER, "ClientBatchCheck");
setHeaderIfNotSet(headers, CLIENT_BULK_REQUEST_ID_HEADER, generateRandomIdWithNonUniqueFallback());

const responses: ClientBatchCheckSingleClientResponse[] = [];
const result: ClientBatchCheckSingleClientResponse[] = [];
for await (const singleCheckResponse of asyncPool(maxParallelRequests, body, (tuple) => this.check(tuple, { ...options, headers })
.then(response => {
(response as ClientBatchCheckSingleClientResponse)._request = tuple;
Expand All @@ -650,9 +650,9 @@ export class {{appShortName}}Client extends BaseAPI {
};
})
)) {
responses.push(singleCheckResponse);
result.push(singleCheckResponse);
}
return { responses };
return { result };
}


Expand Down Expand Up @@ -825,12 +825,12 @@ export class {{appShortName}}Client extends BaseAPI {
context,
})), { ...options, headers, maxParallelRequests });

const firstErrorResponse = batchCheckResults.responses.find(response => (response as any).error);
const firstErrorResponse = batchCheckResults.result.find(response => (response as any).error);
if (firstErrorResponse) {
throw (firstErrorResponse as any).error;
}

return { relations: batchCheckResults.responses.filter(result => result.allowed).map(result => result._request.relation) };
return { relations: batchCheckResults.result.filter(result => result.allowed).map(result => result._request.relation) };
}

/**
Expand Down
4 changes: 2 additions & 2 deletions config/clients/js/template/tests/client.test.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ describe("{{appTitleCaseName}} Client", () => {
expect(scope1.isDone()).toBe(true);
expect(scope2.isDone()).toBe(true);
expect(scope3.isDone()).toBe(false);
expect(response.responses.length).toBe(3);
expect(response.responses.sort((a, b) => String(a._request.object).localeCompare(b._request.object)))
expect(response.result.length).toBe(3);
expect(response.result.sort((a, b) => String(a._request.object).localeCompare(b._request.object)))
.toMatchObject(expect.arrayContaining([
{ _request: tuples[0], allowed: true, },
{ _request: tuples[1], allowed: false },
Expand Down

0 comments on commit 8d32ee2

Please sign in to comment.