Skip to content

Commit

Permalink
feat(signature-collection): send email to lks and skra (#16445)
Browse files Browse the repository at this point in the history
* feat: send email to lks and skra

* chore: nx format:write update dirty files

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 17, 2024
1 parent 0b6981a commit 342c2d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { EmailTemplateGenerator } from '../../../../../types'
import { CreateListSchema } from '@island.is/application/templates/signature-collection/presidential-list-creation'
import { OwnerInput } from '@island.is/clients/signature-collection'
import { SignatureCollection } from '../types'
import { Message, Body } from '@island.is/email-service'
import { CreateListSchema } from '@island.is/application/templates/signature-collection/parliamentary-list-creation'

export const generateApplicationSubmittedEmail: EmailTemplateGenerator = (
props,
Expand All @@ -13,16 +12,14 @@ export const generateApplicationSubmittedEmail: EmailTemplateGenerator = (
} = props

const answers = application.answers as CreateListSchema

const owner: OwnerInput = answers.applicant
const currentCollection: SignatureCollection = application.externalData
.currentCollection?.data as SignatureCollection

const subject = 'Ný meðmælasöfnun hefur verið stofnuð'
const lists: Body[] = currentCollection.areas.map((area) => {
const subject = 'Ný meðmælasöfnun fyrir alþingiskosningar hefur verið stofnuð'
const areas: Body[] = answers.constituency.map((c) => {
return {
component: 'Copy',
context: { copy: `${owner.name} - ${area.name}` },
context: { copy: `${c.split('|')[1]}` },
align: 'left',
}
})

Expand All @@ -49,14 +46,16 @@ export const generateApplicationSubmittedEmail: EmailTemplateGenerator = (
{
component: 'Copy',
context: {
copy: `${owner.name} Kt: ${owner.nationalId} hefur stofnað eftirfarandi lista til meðmælasöfnunar:`,
copy: `${owner.name} Kt: ${owner.nationalId} hefur stofnað lista fyrir flokkinn ${answers.list.name} með listabókstaf ${answers.list.letter} til meðmælasöfnunar fyrir alþingiskosningar í eftirfarandi kjördæmum:`,
align: 'left',
},
},
...lists,
...areas,
{
component: 'Copy',
context: {
copy: `Samskiptaupplýsingar framboðs. Sími ${owner.phone} Netfang: ${owner.email} `,
align: 'left',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { CollectionType } from '@island.is/clients/signature-collection'
import { CreateListSchema } from '@island.is/application/templates/signature-collection/parliamentary-list-creation'
import { FetchError } from '@island.is/clients/middlewares'
import { NationalRegistryClientService } from '@island.is/clients/national-registry-v2'
import { isCompany } from 'kennitala'
import { coreErrorMessages } from '@island.is/application/core'
import { generateApplicationSubmittedEmail } from './emailGenerators'
import { AuthDelegationType } from '@island.is/shared/types'

@Injectable()
export class ParliamentaryListCreationService extends BaseTemplateApiService {
constructor(
@Inject(LOGGER_PROVIDER) private logger: Logger,
private readonly _sharedTemplateAPIService: SharedTemplateApiService,
private readonly sharedTemplateAPIService: SharedTemplateApiService,
private signatureCollectionClientService: SignatureCollectionClientService,
private nationalRegisryClientService: NationalRegistryClientService,
) {
Expand Down Expand Up @@ -154,6 +153,19 @@ export class ParliamentaryListCreationService extends BaseTemplateApiService {
)
})

try {
// Use the shared service to send an email using a custom email generator
await this.sharedTemplateAPIService.sendEmail(
generateApplicationSubmittedEmail,
application,
)
} catch (e) {
this.logger.warn(
'Could not send submit email to admins for parlimentary list creation application: ',
application.id,
)
}

return {
success: true,
slug: result.slug,
Expand Down

0 comments on commit 342c2d8

Please sign in to comment.