From 9bb8115ea9211cfdcca5ff13cafd9972e5d6bf55 Mon Sep 17 00:00:00 2001 From: albinagu <47886428+albinagu@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:22:54 +0000 Subject: [PATCH] fix(inheritance-report): Hotfix for inheritance report uploaded files (#17342) * fix(inheritance-report): Fixes for go live (#17295) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * fix(inheritance-report): bugfixing 20.12 (#17322) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * fix(inheritance-report): Send uploaded files data to syslumenn (#17325) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: juni-haukur <158475136+juni-haukur@users.noreply.github.com> --- .../inheritance-report.module.ts | 2 + .../inheritance-report.service.ts | 53 ++++++++++++++++++- .../inheritance-report/src/lib/dataSchema.ts | 8 +++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/inheritance-report.module.ts b/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/inheritance-report.module.ts index 3e22223815d3..b69ac6eeb172 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/inheritance-report.module.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/inheritance-report.module.ts @@ -5,12 +5,14 @@ import { SyslumennClientModule } from '@island.is/clients/syslumenn' import { InheritanceReportService } from './inheritance-report.service' import { NationalRegistryXRoadModule } from '@island.is/api/domains/national-registry-x-road' +import { AwsModule } from '@island.is/nest/aws' @Module({ imports: [ SharedTemplateAPIModule, SyslumennClientModule, NationalRegistryXRoadModule, + AwsModule, ], providers: [InheritanceReportService], exports: [InheritanceReportService], diff --git a/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/inheritance-report.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/inheritance-report.service.ts index 3edd5317d203..ca260f1cf23d 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/inheritance-report.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/inheritance-report.service.ts @@ -1,5 +1,6 @@ import { Inject, Injectable } from '@nestjs/common' import { + Attachment, DataUploadResponse, Person, PersonType, @@ -18,6 +19,7 @@ import { inheritanceReportSchema } from '@island.is/application/templates/inheri import type { Logger } from '@island.is/logging' import { expandAnswers } from './utils/mappers' import { NationalRegistryXRoadService } from '@island.is/api/domains/national-registry-x-road' +import { S3Service } from '@island.is/nest/aws' type InheritanceSchema = zinfer @@ -27,6 +29,7 @@ export class InheritanceReportService extends BaseTemplateApiService { @Inject(LOGGER_PROVIDER) private logger: Logger, private readonly syslumennService: SyslumennService, private readonly nationalRegistryService: NationalRegistryXRoadService, + private readonly s3Service: S3Service, ) { super(ApplicationTypes.INHERITANCE_REPORT) } @@ -105,9 +108,44 @@ export class InheritanceReportService extends BaseTemplateApiService { const uploadDataName = 'erfdafjarskysla1.0' const uploadDataId = 'erfdafjarskysla1.0' + const attachments: Attachment[] = [] + + if (answers?.heirsAdditionalInfoPrivateTransferFiles) { + attachments.push( + ...(await Promise.all( + answers.heirsAdditionalInfoPrivateTransferFiles.map(async (file) => { + const content = await this.getFileContentBase64(file.key) + return { + name: file.name, + content, + } + }), + )), + ) + } + + if (answers?.heirsAdditionalInfoFilesOtherDocuments) { + attachments.push( + ...(await Promise.all( + answers.heirsAdditionalInfoFilesOtherDocuments.map(async (file) => { + const content = await this.getFileContentBase64(file.key) + return { + name: file.name, + content, + } + }), + )), + ) + } const result: DataUploadResponse = await this.syslumennService - .uploadData([person], undefined, uploadData, uploadDataName, uploadDataId) + .uploadData( + [person], + attachments, + uploadData, + uploadDataName, + uploadDataId, + ) .catch((e) => { return { success: false, @@ -131,4 +169,17 @@ export class InheritanceReportService extends BaseTemplateApiService { const spouse = await this.nationalRegistryService.getSpouse(auth.nationalId) return { ...spouse, fullName: spouse?.name } } + + async getFileContentBase64(fileName: string): Promise { + try { + const fileContent = await this.s3Service.getFileContent( + fileName, + 'base64', + ) + return fileContent || '' + } catch (e) { + this.logger.warn('[estate]: Failed to get file content - ', e) + return 'err' + } + } } diff --git a/libs/application/templates/inheritance-report/src/lib/dataSchema.ts b/libs/application/templates/inheritance-report/src/lib/dataSchema.ts index 2e369699cc60..054423f72638 100644 --- a/libs/application/templates/inheritance-report/src/lib/dataSchema.ts +++ b/libs/application/templates/inheritance-report/src/lib/dataSchema.ts @@ -676,6 +676,14 @@ export const inheritanceReportSchema = z.object({ }), heirsAdditionalInfo: z.string().optional(), + heirsAdditionalInfoPrivateTransferFiles: z + .object({ key: z.string(), name: z.string() }) + .array() + .optional(), + heirsAdditionalInfoFilesOtherDocuments: z + .object({ key: z.string(), name: z.string() }) + .array() + .optional(), spouse: z .object({