Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#174644239] - Fix GetServices returns all services #68

Merged
merged 2 commits into from
Sep 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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