Skip to content

Commit

Permalink
[#174644239] - Fix GetServices returns all services (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleDore authored Sep 3, 2020
1 parent f1e9b5f commit ce57f1a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions GetServices/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import {
import { isLeft } from "fp-ts/lib/Either";
import { collect, StrMap } from "fp-ts/lib/StrMap";
import { tryCatch } from "fp-ts/lib/TaskEither";
import { mapAsyncIterator } from "io-functions-commons/dist/src/utils/async";
import {
asyncIteratorToArray,
mapAsyncIterator
} from "io-functions-commons/dist/src/utils/async";
import { toCosmosErrorResponse } from "io-functions-commons/dist/src/utils/cosmosdb_model";
import {
IResponseSuccessJson,
Expand Down Expand Up @@ -69,12 +72,22 @@ export function GetServicesHandler(
}, {})
);

return tryCatch(() => allServicesIterator.next(), toCosmosErrorResponse)
return tryCatch(
() => asyncIteratorToArray(allServicesIterator),
toCosmosErrorResponse
)
.fold<IGetServicesHandlerResult>(
error => ResponseErrorQuery("Cannot get services", error),
iteratorResults => {
results => {
// tslint:disable-next-line: no-inferred-empty-object-type
const reducedResults = results.reduce((prev, curr) => {
return {
...prev,
...curr
};
}, {});
const items = collect(
new StrMap(iteratorResults.value),
new StrMap(reducedResults),
(_____, v: ApiService) => v
);
// FIXME: make response iterable over results pages
Expand Down

0 comments on commit ce57f1a

Please sign in to comment.