Skip to content

Commit

Permalink
Merge branch 'main' into fix/web-temporary-event-licence-boolean-check
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Oct 21, 2024
2 parents 296e3a6 + 7c83ad4 commit f07d048
Show file tree
Hide file tree
Showing 14 changed files with 365 additions and 110 deletions.
2 changes: 2 additions & 0 deletions apps/application-system/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { FriggClientConfig } from '@island.is/clients/mms/frigg'
import { smsModuleConfig } from '@island.is/nova-sms'
import { emailModuleConfig } from '@island.is/email-service'
import { sharedModuleConfig } from '@island.is/application/template-api-modules'
import { UserNotificationClientConfig } from '@island.is/clients/user-notification'

@Module({
imports: [
Expand Down Expand Up @@ -119,6 +120,7 @@ import { sharedModuleConfig } from '@island.is/application/template-api-modules'
smsModuleConfig,
emailModuleConfig,
sharedModuleConfig,
UserNotificationClientConfig,
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { SyslumennClientModule } from '@island.is/clients/syslumenn'
import { NationalRegistryClientModule } from '@island.is/clients/national-registry-v2'
import { SharedTemplateAPIModule } from '../../shared'
import { SmsModule } from '@island.is/nova-sms'
import { ApplicationsNotificationsModule } from '../../../notification/notifications.module'

@Module({
imports: [
SyslumennClientModule,
SharedTemplateAPIModule,
SmsModule,
NationalRegistryClientModule,
ApplicationsNotificationsModule,
],
providers: [ChildrenResidenceChangeServiceV2],
exports: [ChildrenResidenceChangeServiceV2],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Injectable } from '@nestjs/common'
import { TemplateApiModuleActionProps } from '../../../types'
import { Inject, Injectable } from '@nestjs/common'
import {
SharedModuleConfig,
TemplateApiModuleActionProps,
} from '../../../types'
import {
SyslumennService,
Person,
Expand All @@ -14,20 +17,17 @@ import {
import { Override } from '@island.is/application/templates/family-matters-core/types'
import { CRCApplication } from '@island.is/application/templates/children-residence-change-v2'
import { SharedTemplateApiService } from '../../shared'
import {
applicationRejectedByOrganizationEmail,
generateApplicationSubmittedEmail,
generateSyslumennNotificationEmail,
transferRequestedEmail,
} from './emailGenerators'
import { generateSyslumennNotificationEmail } from './emailGenerators'
import { Application, ApplicationTypes } from '@island.is/application/types'
import { SmsService } from '@island.is/nova-sms'
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 { isValidNumberForRegion } from 'libphonenumber-js'
import { generateResidenceChangePdf } from './pdfGenerators'
import { NotificationsService } from '../../../notification/notifications.service'
import { NotificationType } from '../../../notification/notificationsTemplates'
import { getSlugFromType } from '@island.is/application/core'
import { ConfigService } from '@nestjs/config'
import { getConfigValue } from '../../shared/shared.utils'

type Props = Override<
TemplateApiModuleActionProps,
Expand All @@ -39,8 +39,8 @@ export class ChildrenResidenceChangeServiceV2 extends BaseTemplateApiService {
constructor(
private readonly syslumennService: SyslumennService,
private readonly sharedTemplateAPIService: SharedTemplateApiService,
private readonly smsService: SmsService,
private nationalRegistryApi: NationalRegistryClientService,
private readonly notificationsService: NotificationsService,
private readonly configService: ConfigService<SharedModuleConfig>,
) {
super(ApplicationTypes.CHILDREN_RESIDENCE_CHANGE_V2)
}
Expand Down Expand Up @@ -166,82 +166,160 @@ export class ChildrenResidenceChangeServiceV2 extends BaseTemplateApiService {
}

async sendNotificationToCounterParty({ application }: Props) {
const { answers } = application
const { counterParty } = answers
const {
externalData: { nationalRegistry, childrenCustodyInformation },
} = application

if (counterParty.email) {
await this.sharedTemplateAPIService.sendEmail(
transferRequestedEmail,
application as unknown as Application,
)
if (
!childrenCustodyInformation?.data ||
childrenCustodyInformation.data.length === 0
) {
throw new Error('No custody information available')
}

if (counterParty.phoneNumber) {
await this.smsService.sendSms(
counterParty.phoneNumber,
'Þér hafa borist drög að samningi um breytt lögheimili barns á Island.is. Samningurinn er aðgengilegur á island.is/minarsidur undir Umsóknir.',
)
const applicant = nationalRegistry.data
const otherParent = childrenCustodyInformation.data[0].otherParent
const contractLink = await this.getApplicationLink(application)

if (otherParent) {
this.notificationsService.sendNotification({
type: NotificationType.AssignCounterParty,
messageParties: {
recipient: otherParent.nationalId,
sender: applicant.nationalId,
},
args: {
applicantName: applicant.fullName,
contractLink,
},
})
}
}

// Sends notification to both parties
async approvedByOrganization({ application }: Props) {
const { answers, externalData } = application
const { parentA, parentB } = answers
const { nationalRegistry } = externalData
const {
externalData: {
nationalRegistry,
childrenCustodyInformation,
submitApplication,
},
} = application
if (
!childrenCustodyInformation?.data ||
childrenCustodyInformation.data.length === 0
) {
throw new Error('No custody information available')
}
const applicant = nationalRegistry.data
const childResidenceInfo = childrenResidenceInfo(
applicant,
externalData.childrenCustodyInformation.data,
answers.selectedChildren,
)
const caseNumber = externalData.submitApplication?.data?.caseNumber
const otherParent = childrenCustodyInformation.data[0].otherParent
const caseNumber = submitApplication?.data?.caseNumber
const applicationLink = await this.getApplicationLink(application)

if (!childResidenceInfo.future?.address?.postalCode) {
throw new Error('Future residence postal code was not found')
if (!otherParent) {
throw new Error('Other parent was undefined')
}

const pdf = await generateResidenceChangePdf(application)
const syslumennData = syslumennDataFromPostalCode(
childResidenceInfo.future.address.postalCode,
)

await this.sharedTemplateAPIService.sendEmail(
(props) =>
generateApplicationSubmittedEmail(
props,
pdf.toString('binary'),
parentA.email,
syslumennData.name,
caseNumber,
),
application as unknown as Application,
)

await this.sharedTemplateAPIService.sendEmail(
(props) =>
generateApplicationSubmittedEmail(
props,
pdf.toString('binary'),
parentB.email,
syslumennData.name,
caseNumber,
),
application as unknown as Application,
)
this.notificationsService.sendNotification({
type: NotificationType.ChildrenResidenceChangeApprovedByOrg,
messageParties: {
recipient: applicant.nationalId,
},
args: {
applicationLink,
caseNumber: caseNumber || '',
},
})
this.notificationsService.sendNotification({
type: NotificationType.ChildrenResidenceChangeApprovedByOrg,
messageParties: {
recipient: otherParent.nationalId,
},
args: {
applicationLink,
caseNumber: caseNumber || '',
},
})
}

async rejectedByCounterParty({ application }: Props) {
await this.sharedTemplateAPIService.sendEmail(
applicationRejectedEmail,
application as unknown as Application,
)
const {
externalData: { nationalRegistry, childrenCustodyInformation },
} = application
if (
!childrenCustodyInformation?.data ||
childrenCustodyInformation.data.length === 0
) {
throw new Error('No custody information available')
}
const applicant = nationalRegistry.data
const otherParent = childrenCustodyInformation.data[0].otherParent

this.notificationsService.sendNotification({
type: NotificationType.RejectedByCounterParty,
messageParties: {
recipient: applicant.nationalId,
},
args: {
counterPartyName: otherParent?.fullName || '',
},
})
}

async rejectedByOrganization({ application }: Props) {
await this.sharedTemplateAPIService.sendEmail(
applicationRejectedByOrganizationEmail,
application as unknown as Application,
const {
answers,
externalData: { nationalRegistry, childrenCustodyInformation },
} = application
if (
!childrenCustodyInformation?.data ||
childrenCustodyInformation.data.length === 0
) {
throw new Error('No custody information available')
}
const applicant = nationalRegistry.data
const otherParent = childrenCustodyInformation.data[0].otherParent
const childResidenceInfo = childrenResidenceInfo(
applicant,
childrenCustodyInformation.data,
answers.selectedChildren,
)
const syslumennName = syslumennDataFromPostalCode(
childResidenceInfo?.future?.address?.postalCode || '',
).name

if (!otherParent) {
throw new Error('Other parent was undefined')
}

this.notificationsService.sendNotification({
type: NotificationType.RejectedByOrganization,
messageParties: {
recipient: applicant.nationalId,
},
args: {
orgName: syslumennName,
},
})
this.notificationsService.sendNotification({
type: NotificationType.RejectedByOrganization,
messageParties: {
recipient: otherParent.nationalId,
},
args: {
orgName: syslumennName,
},
})
}

private async getApplicationLink(application: CRCApplication) {
const clientLocationOrigin = getConfigValue(
this.configService,
'clientLocationOrigin',
) as string

return `${clientLocationOrigin}/${
getSlugFromType(application.typeId) as string
}/${application.id}` as string
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { SharedTemplateAPIModule } from '../../shared'

// Here you import your module service
import { ReferenceTemplateService } from './reference-template.service'

import { ApplicationsNotificationsModule } from '../../../notification/notifications.module'
@Module({
imports: [SharedTemplateAPIModule],
imports: [SharedTemplateAPIModule, ApplicationsNotificationsModule],
providers: [ReferenceTemplateService],
exports: [ReferenceTemplateService],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,47 @@ import {
import { ApplicationTypes } from '@island.is/application/types'
import { BaseTemplateApiService } from '../../base-template-api.service'
import { TemplateApiError } from '@island.is/nest/problem'
import { NotificationsService } from '../../../notification/notifications.service'
import { NotificationType } from '../../../notification/notificationsTemplates'

const TWO_HOURS_IN_SECONDS = 2 * 60 * 60
@Injectable()
export class ReferenceTemplateService extends BaseTemplateApiService {
constructor(
private readonly sharedTemplateAPIService: SharedTemplateApiService,
private readonly notificationsService: NotificationsService,
) {
super(ApplicationTypes.EXAMPLE)
}

async getReferenceData({ application }: TemplateApiModuleActionProps) {
async getReferenceData({ application, auth }: TemplateApiModuleActionProps) {
await new Promise((resolve) => setTimeout(resolve, 2000))

const applicantName = getValueViaPath(
application.externalData,
'nationalRegistry.data.fullName',
) as string

this.notificationsService.sendNotification({
type: NotificationType.ChildrenResidenceChange,
messageParties: {
recipient: auth.nationalId,
sender: auth.nationalId,
},
args: {
applicantName,
applicationId: application.id,
},
})

const name = getValueViaPath(
application.externalData,
'nationalRegistry.data.name',
'nationalRegistry.data.fullName',
) as string

return {
referenceData: {
name,
applicantName,
some: 'data',
numbers: 123,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { NotificationConfig, NotificationType } from './notificationsTemplates'

export type NotificationConfigType = typeof NotificationConfig
export type NotificationTypeKey = keyof typeof NotificationConfig
export type NotificationArgs<T extends NotificationTypeKey> =
NotificationConfigType[T]['keys']
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common'

import { UserNotificationClientModule } from '@island.is/clients/user-notification'
import { NotificationsService } from './notifications.service'

@Module({
imports: [UserNotificationClientModule],
providers: [NotificationsService],
exports: [NotificationsService],
})
export class ApplicationsNotificationsModule {}
Loading

0 comments on commit f07d048

Please sign in to comment.