Skip to content

Commit

Permalink
fix(inheritance-report): Send uploaded files data to syslumenn (#17325)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
juni-haukur and kodiakhq[bot] authored Dec 20, 2024
1 parent 1826987 commit 8d0e092
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Inject, Injectable } from '@nestjs/common'
import {
Attachment,
DataUploadResponse,
Person,
PersonType,
Expand All @@ -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<typeof inheritanceReportSchema>

Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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<string> {
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'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 8d0e092

Please sign in to comment.