Skip to content

Commit

Permalink
reverted changes to a file that will be deleted on main anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
HjorturJ committed Sep 12, 2024
1 parent 8a77e89 commit 1e87112
Showing 1 changed file with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@island.is/application/templates/family-matters-core/utils'
import { Override } from '@island.is/application/templates/family-matters-core/types'
import { CRCApplication } from '@island.is/application/templates/children-residence-change'
import { S3 } from 'aws-sdk'
import { SharedTemplateApiService } from '../../shared'
import {
generateApplicationSubmittedEmail,
Expand All @@ -25,7 +26,6 @@ import { syslumennDataFromPostalCode } from './utils'
import { applicationRejectedEmail } from './emailGenerators/applicationRejected'
import { BaseTemplateApiService } from '../../base-template-api.service'
import { NationalRegistryClientService } from '@island.is/clients/national-registry-v2'
import { AwsService } from '@island.is/nest/aws'

export const PRESIGNED_BUCKET = 'PRESIGNED_BUCKET'

Expand All @@ -36,31 +36,28 @@ type props = Override<

@Injectable()
export class ChildrenResidenceChangeService extends BaseTemplateApiService {
s3: S3

constructor(
private readonly syslumennService: SyslumennService,
@Inject(PRESIGNED_BUCKET) private readonly presignedBucket: string,
private readonly sharedTemplateAPIService: SharedTemplateApiService,
private readonly smsService: SmsService,
private nationalRegistryApi: NationalRegistryClientService,
private readonly awsService: AwsService,
) {
super(ApplicationTypes.CHILDREN_RESIDENCE_CHANGE)
this.s3 = new S3()
}

async submitApplication({ application }: props) {
const { answers, externalData } = application
const { nationalRegistry } = externalData
const applicant = nationalRegistry.data
const s3FileName = `children-residence-change/${application.id}.pdf`
const file = await this.awsService.getFile({
bucket: this.presignedBucket,
key: s3FileName,
})
if (!file) {
throw new Error('File content was undefined')
}

const fileContent = await file?.Body?.transformToString()
const file = await this.s3
.getObject({ Bucket: this.presignedBucket, Key: s3FileName })
.promise()
const fileContent = file.Body as Buffer

const selectedChildren = getSelectedChildrenFromExternalData(
externalData.childrenCustodyInformation.data,
Expand All @@ -79,13 +76,11 @@ export class ChildrenResidenceChangeService extends BaseTemplateApiService {
if (!fileContent) {
throw new Error('File content was undefined')
}
const fileContentBase64 = Buffer.from(fileContent).toString('base64')
const fileContentBinary = Buffer.from(fileContent).toString('binary')

const attachments: Attachment[] = [
{
name: `Lögheimilisbreyting-barns-${applicant.nationalId}.pdf`,
content: fileContentBase64,
content: fileContent.toString('base64'),
},
]

Expand Down Expand Up @@ -157,7 +152,7 @@ export class ChildrenResidenceChangeService extends BaseTemplateApiService {
await this.sharedTemplateAPIService.sendEmailWithAttachment(
generateSyslumennNotificationEmail,
application as unknown as Application,
fileContentBinary,
fileContent.toString('binary'),
syslumennData.email,
)
return undefined
Expand All @@ -167,7 +162,7 @@ export class ChildrenResidenceChangeService extends BaseTemplateApiService {
(props) =>
generateApplicationSubmittedEmail(
props,
fileContentBinary,
fileContent.toString('binary'),
answers.parentA.email,
syslumennData.name,
response?.caseNumber,
Expand All @@ -179,7 +174,7 @@ export class ChildrenResidenceChangeService extends BaseTemplateApiService {
(props) =>
generateApplicationSubmittedEmail(
props,
fileContentBinary,
fileContent.toString('binary'),
answers.parentB.email,
syslumennData.name,
response?.caseNumber,
Expand Down

0 comments on commit 1e87112

Please sign in to comment.