From 55aae3d129b0ce17429d2bf35be1e45ab4c38433 Mon Sep 17 00:00:00 2001 From: helgifr Date: Fri, 13 Dec 2024 15:38:44 +0000 Subject: [PATCH] fix(parental-leave): pdf attachments not uploading (#17114) Co-authored-by: hfhelgason Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../parental-leave/parental-leave.service.ts | 72 ++++++++++--------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts index 8d064e4ce24f..2fdc49ef12d8 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts @@ -35,6 +35,7 @@ import { getAdditionalSingleParentRightsInMonths, clamp, getMultipleBirthsDaysInMonths, + Files, } from '@island.is/application/templates/parental-leave' import { Application, @@ -402,6 +403,23 @@ export class ParentalLeaveService extends BaseTemplateApiService { } } + async getPDFs( + application: Application, + documents: Files[], + attachmentType: string, + fileUpload: string, + ) { + const PDFs = [] + for (const index of documents.keys()) { + const pdf = await this.getPdf(application, index, fileUpload) + PDFs.push({ + attachmentType, + attachmentBytes: pdf, + }) + } + return PDFs + } + async getAttachments(application: Application): Promise { const attachments: Attachment[] = [] const { @@ -433,48 +451,36 @@ export class ParentalLeaveService extends BaseTemplateApiService { state === States.RESIDENCE_GRANT_APPLICATION ) { if (residenceGrantFiles) { - residenceGrantFiles.forEach(async (item, index) => { - const pdf = await this.getPdf( - application, - index, - 'fileUpload.residenceGrant', - ) - attachments.push({ - attachmentType: apiConstants.attachments.residenceGrant, - attachmentBytes: pdf, - }) - }) + const PDFs = await this.getPDFs( + application, + residenceGrantFiles, + apiConstants.attachments.residenceGrant, + 'fileUpload.residenceGrant', + ) + attachments.push(...PDFs) } } if (changeEmployerFile) { - changeEmployerFile.forEach(async (item, index) => { - const pdf = await this.getPdf( - application, - index, - 'fileUpload.changeEmployerFile', - ) - attachments.push({ - attachmentType: apiConstants.attachments.changeEmployer, - attachmentBytes: pdf, - }) - }) + const PDFs = await this.getPDFs( + application, + changeEmployerFile, + apiConstants.attachments.changeEmployer, + 'fileUpload.changeEmployerFile', + ) + attachments.push(...PDFs) } // We don't want to send old files to VMST again if (applicationFundId && applicationFundId !== '') { if (additionalDocuments) { - for (const index of additionalDocuments.keys()) { - const pdf = await this.getPdf( - application, - index, - 'fileUpload.additionalDocuments', - ) - attachments.push({ - attachmentType: apiConstants.attachments.other, - attachmentBytes: pdf, - }) - } + const PDFs = await this.getPDFs( + application, + additionalDocuments, + apiConstants.attachments.other, + 'fileUpload.additionalDocuments', + ) + attachments.push(...PDFs) } return attachments }