From 8c6e287026a329a648b0793e3b4a763d5af18154 Mon Sep 17 00:00:00 2001 From: Benjamin Petetot Date: Thu, 7 Nov 2024 11:02:11 +0100 Subject: [PATCH] feat(api): build account creation email with EmailFactory --- .../domain/emails/account-creation.email.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 api/src/identity-access-management/domain/emails/account-creation.email.js diff --git a/api/src/identity-access-management/domain/emails/account-creation.email.js b/api/src/identity-access-management/domain/emails/account-creation.email.js new file mode 100644 index 00000000000..6162875c79e --- /dev/null +++ b/api/src/identity-access-management/domain/emails/account-creation.email.js @@ -0,0 +1,35 @@ +import { urlBuilder } from '../../../shared/infrastructure/utils/url-builder.js'; +import { EmailFactory } from '../../../shared/mail/domain/models/EmailFactory.js'; +import { mailer } from '../../../shared/mail/infrastructure/services/mailer.js'; + +export function createAccountCreationEmail({ locale, email, firstName, token, redirectionUrl }) { + const { buildEmail, i18n, defaultVariables } = new EmailFactory({ app: 'pix-app', locale }); + + const redirectUrl = redirectionUrl || defaultVariables.pixAppConnectionUrl; + + return buildEmail({ + template: mailer.accountCreationTemplateId, + subject: i18n.__('pix-account-creation-email.subject'), + to: email, + variables: { + homeName: defaultVariables.homeName, + homeUrl: defaultVariables.homeUrl, + helpdeskUrl: defaultVariables.helpdeskUrl, + displayNationalLogo: defaultVariables.displayNationalLogo, + askForHelp: i18n.__('pix-account-creation-email.params.askForHelp'), + disclaimer: i18n.__('pix-account-creation-email.params.disclaimer'), + doNotAnswer: i18n.__('pix-account-creation-email.params.doNotAnswer'), + goToPix: i18n.__('pix-account-creation-email.params.goToPix'), + helpdeskLinkLabel: i18n.__('pix-account-creation-email.params.helpdeskLinkLabel'), + moreOn: i18n.__('pix-account-creation-email.params.moreOn'), + pixPresentation: i18n.__('pix-account-creation-email.params.pixPresentation'), + subtitle: i18n.__('pix-account-creation-email.params.subtitle'), + subtitleDescription: i18n.__('pix-account-creation-email.params.subtitleDescription'), + title: i18n.__('pix-account-creation-email.params.title', { firstName }), + redirectionUrl: urlBuilder.getEmailValidationUrl({ locale, redirectUrl, token }), + }, + }); +} + +// const email = createAccountCreationEmail({ ... }); +// await emailRepository.send(email);