From ce57f1a74045633a6edcc0e4b29d4f2cbd9e4861 Mon Sep 17 00:00:00 2001 From: Alessio Dore <57567806+AleDore@users.noreply.github.com> Date: Thu, 3 Sep 2020 17:02:12 +0200 Subject: [PATCH] [#174644239] - Fix GetServices returns all services (#68) --- GetServices/handler.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/GetServices/handler.ts b/GetServices/handler.ts index fdc0084d..9d15ec36 100644 --- a/GetServices/handler.ts +++ b/GetServices/handler.ts @@ -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, @@ -69,12 +72,22 @@ export function GetServicesHandler( }, {}) ); - return tryCatch(() => allServicesIterator.next(), toCosmosErrorResponse) + return tryCatch( + () => asyncIteratorToArray(allServicesIterator), + toCosmosErrorResponse + ) .fold( 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