From a8d3c96d6deba77ef63f51bd5e2997f12cfa5224 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 30 Nov 2023 16:01:01 +0300 Subject: [PATCH] apps/web: combineDocuments: add missing documentTypes to res --- apps/web/api/ius/tools.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/web/api/ius/tools.ts b/apps/web/api/ius/tools.ts index f87a744..60011b6 100644 --- a/apps/web/api/ius/tools.ts +++ b/apps/web/api/ius/tools.ts @@ -12,12 +12,20 @@ export function combineDocuments({ return documentTypes.map((x) => ({ ...(x as Document), canUpload: true })); } - return unique(documents, ({ documentTypeId }) => documentTypeId).map((document) => ({ + const res = unique(documents, ({ documentTypeId }) => documentTypeId).map((document) => ({ ...document, canUpload: documentTypes.some( (documentType) => documentType.documentTypeId === document.documentTypeId ), })); + + documentTypes.forEach((documentType) => { + if (!res.some((document) => document.documentTypeId === documentType.documentTypeId)) { + res.push({ ...documentType, canUpload: true }); + } + }); + + return res; } export type CombinedDocuments = ReturnType;