Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inheritance-report): Send uploaded files data to syslumenn #17325

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
}),
)),
)
}

juni-haukur marked this conversation as resolved.
Show resolved Hide resolved
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,
}
}),
)),
)
}
juni-haukur marked this conversation as resolved.
Show resolved Hide resolved

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'
}
}
juni-haukur marked this conversation as resolved.
Show resolved Hide resolved
}
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
Loading