diff --git a/dictation_server/src/features/accounts/accounts.service.spec.ts b/dictation_server/src/features/accounts/accounts.service.spec.ts index 1a6b85b..bbde671 100644 --- a/dictation_server/src/features/accounts/accounts.service.spec.ts +++ b/dictation_server/src/features/accounts/accounts.service.spec.ts @@ -5561,6 +5561,12 @@ describe('アカウント情報更新', () => { const module = await makeTestingModule(source); if (!module) fail(); const service = module.get(AccountsService); + overrideSendgridService(service, { + sendMail: async () => { + return; + }, + }); + const { tier4Accounts: tier4Accounts } = await makeHierarchicalAccounts( source, ); @@ -5590,6 +5596,11 @@ describe('アカウント情報更新', () => { const module = await makeTestingModule(source); if (!module) fail(); const service = module.get(AccountsService); + overrideSendgridService(service, { + sendMail: async () => { + return; + }, + }); const { tier3Accounts: tier3Accounts, tier4Accounts: tier4Accounts } = await makeHierarchicalAccounts(source); const adduser = await makeTestUser(source, { @@ -5619,6 +5630,11 @@ describe('アカウント情報更新', () => { const module = await makeTestingModule(source); if (!module) fail(); const service = module.get(AccountsService); + overrideSendgridService(service, { + sendMail: async () => { + return; + }, + }); const { tier4Accounts: tier4Accounts } = await makeHierarchicalAccounts( source, ); @@ -5649,6 +5665,11 @@ describe('アカウント情報更新', () => { const module = await makeTestingModule(source); if (!module) fail(); const service = module.get(AccountsService); + overrideSendgridService(service, { + sendMail: async () => { + return; + }, + }); const { tier4Accounts: tier4Accounts } = await makeHierarchicalAccounts( source, ); @@ -5676,6 +5697,11 @@ describe('アカウント情報更新', () => { const module = await makeTestingModule(source); if (!module) fail(); const service = module.get(AccountsService); + overrideSendgridService(service, { + sendMail: async () => { + return; + }, + }); const { tier4Accounts: tier4Accounts } = await makeHierarchicalAccounts( source, ); @@ -5702,6 +5728,11 @@ describe('アカウント情報更新', () => { const module = await makeTestingModule(source); if (!module) fail(); const service = module.get(AccountsService); + overrideSendgridService(service, { + sendMail: async () => { + return; + }, + }); const { tier4Accounts: tier4Accounts } = await makeHierarchicalAccounts( source, ); diff --git a/dictation_server/src/features/accounts/accounts.service.ts b/dictation_server/src/features/accounts/accounts.service.ts index e913c27..2b0eb8f 100644 --- a/dictation_server/src/features/accounts/accounts.service.ts +++ b/dictation_server/src/features/accounts/accounts.service.ts @@ -2075,7 +2075,7 @@ export class AccountsService { ); try { - const { account_id: accountId } = + const { account_id: accountId, account } = await this.usersRepository.findUserByExternalId(context, externalId); await this.accountRepository.updateAccountInfo( context, @@ -2086,6 +2086,52 @@ export class AccountsService { parentAccountId, secondryAdminUserId, ); + + // メール送信処理 + try { + if (account === null) { + throw new Error(`account not found. accountId: ${accountId}`); + } + + let dealerName: string | null = null; + if (parentAccountId !== undefined) { + const dealer = await this.accountRepository.findAccountById( + context, + parentAccountId, + ); + dealerName = dealer.company_name; + } + + const { external_id: externalId } = + await this.usersRepository.findUserById(context, primaryAdminUserId); + + const primaryAdmin = await this.adB2cService.getUser( + context, + externalId, + ); + + const { + displayName: primaryAdminName, + emailAddress: primaryAdminEmail, + } = getUserNameAndMailAddress(primaryAdmin); + + if (!primaryAdminEmail) { + throw new Error( + `adb2c user mail not found. externalId: ${externalId}`, + ); + } + + await this.sendgridService.sendMailWithU112( + context, + primaryAdminName, + primaryAdminEmail, + account.company_name, + dealerName, + ); + } catch (e) { + this.logger.error(`[${context.getTrackingId()}] error=${e}`); + // メール送信に関する例外はログだけ出して握りつぶす + } } catch (e) { this.logger.error(`[${context.getTrackingId()}] error=${e}`); if (e instanceof Error) { diff --git a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts index a5b3c92..25d32ea 100644 --- a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts +++ b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts @@ -42,6 +42,11 @@ export class SendGridService { private readonly templateU109Text: string; private readonly templateU111Html: string; private readonly templateU111Text: string; + private readonly templateU112Html: string; + private readonly templateU112Text: string; + // U-112のテンプレート差分(親アカウントがない場合) + private readonly templateU112NoParentHtml: string; + private readonly templateU112NoParentText: string; private readonly templateU117Html: string; private readonly templateU117Text: string; @@ -127,6 +132,26 @@ export class SendGridService { 'utf-8', ); + this.templateU112Html = readFileSync( + path.resolve(__dirname, `../../templates/template_U_112.html`), + 'utf-8', + ); + this.templateU112Text = readFileSync( + path.resolve(__dirname, `../../templates/template_U_112.txt`), + 'utf-8', + ); + this.templateU112NoParentHtml = readFileSync( + path.resolve( + __dirname, + `../../templates/template_U_112_no_parent.html`, + ), + 'utf-8', + ); + this.templateU112NoParentText = readFileSync( + path.resolve(__dirname, `../../templates/template_U_112_no_parent.txt`), + 'utf-8', + ); + this.templateU117Html = readFileSync( path.resolve(__dirname, `../../templates/template_U_117.html`), 'utf-8', @@ -602,6 +627,72 @@ export class SendGridService { } } + /** + * U-112のテンプレートを使用したメールを送信する + * @param context + * @param primaryAdminName 情報変更を行ったアカウントの管理者(primary)の名前 + * @param primaryAdminMail 情報変更を行ったアカウントの管理者(primary)のメールアドレス + * @param customerAccountName 情報変更を行ったアカウントの名前 + * @param dealerAccountName 問題発生時に問い合わせする先の上位のディーラー名(会社名) + * @returns mail with u112 + */ + async sendMailWithU112( + context: Context, + primaryAdminName: string, + primaryAdminMail: string, + customerAccountName: string, + dealerAccountName: string | null, + ): Promise { + this.logger.log( + `[IN] [${context.getTrackingId()}] ${this.sendMailWithU112.name}`, + ); + try { + const subject = 'Account Edit Notification [U-112]'; + + let html: string; + let text: string; + + // 親アカウントがない場合は別のテンプレートを使用する + if (dealerAccountName === null) { + // メールの本文を作成する + html = this.templateU112NoParentHtml + .replaceAll(CUSTOMER_NAME, customerAccountName) + .replaceAll(PRIMARY_ADMIN_NAME, primaryAdminName) + .replaceAll(TOP_URL, this.appDomain); + text = this.templateU112NoParentText + .replaceAll(CUSTOMER_NAME, customerAccountName) + .replaceAll(PRIMARY_ADMIN_NAME, primaryAdminName) + .replaceAll(TOP_URL, this.appDomain); + } else { + html = this.templateU112Html + .replaceAll(CUSTOMER_NAME, customerAccountName) + .replaceAll(DEALER_NAME, dealerAccountName) + .replaceAll(PRIMARY_ADMIN_NAME, primaryAdminName) + .replaceAll(TOP_URL, this.appDomain); + text = this.templateU112Text + .replaceAll(CUSTOMER_NAME, customerAccountName) + .replaceAll(DEALER_NAME, dealerAccountName) + .replaceAll(PRIMARY_ADMIN_NAME, primaryAdminName) + .replaceAll(TOP_URL, this.appDomain); + } + + // メールを送信する + this.sendMail( + context, + [primaryAdminMail], + [], + this.mailFrom, + subject, + text, + html, + ); + } finally { + this.logger.log( + `[OUT] [${context.getTrackingId()}] ${this.sendMailWithU112.name}`, + ); + } + } + /** * U-117のテンプレートを使用したメールを送信する * @param context diff --git a/dictation_server/src/templates/template_U_112.html b/dictation_server/src/templates/template_U_112.html new file mode 100644 index 0000000..cd10847 --- /dev/null +++ b/dictation_server/src/templates/template_U_112.html @@ -0,0 +1,66 @@ + + + Account Edit Notification [U-112] + + +
+

<English>

+

Dear $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$

+

+ Your account information has been edited successfully. To check or + change your company's account information, please log in to ODMS + Cloud.
+ URL: $TOP_URL$ +

+

+ If you need support regarding ODMS Cloud, please contact $DEALER_NAME$. +

+

+ If you have received this e-mail in error, please delete this e-mail + from your system.
+ This is an automatically generated e-mail and this mailbox is not + monitored. Please do not reply. +

+
+
+

<Deutsch>

+

Sehr geehrte(r) $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$

+

+ Ihre Kontoinformationen wurden erfolgreich bearbeitet. Um die + Kontoinformationen Ihres Unternehmens zu überprüfen oder zu ändern, + melden Sie sich bitte bei ODMS Cloud an.
+ URL: $TOP_URL$ +

+

+ Wenn Sie Unterstützung bezüglich ODMS Cloud benötigen, wenden Sie sich + bitte an $DEALER_NAME$. +

+

+ Wenn Sie diese E-Mail fälschlicherweise erhalten haben, löschen Sie + diese E-Mail bitte aus Ihrem System.
+ Dies ist eine automatisch generierte E-Mail und dieses Postfach wird + nicht überwacht. Bitte nicht antworten. +

+
+
+

<Français>

+

Chère/Cher $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$

+

+ Les informations de votre compte ont été modifiées avec succès. Pour + vérifier ou modifier les informations du compte de votre entreprise, + veuillez vous connecter à ODMS Cloud.
+ URL: $TOP_URL$ +

+

+ Si vous avez besoin d'assistance concernant ODMS Cloud, veuillez + contacter $DEALER_NAME$. +

+

+ Si vous avez reçu cet e-mail par erreur, veuillez supprimer cet e-mail + de votre système.
+ Il s'agit d'un e-mail généré automatiquement et cette boîte aux lettres + n'est pas surveillée. Merci de ne pas répondre. +

+
+ + diff --git a/dictation_server/src/templates/template_U_112.txt b/dictation_server/src/templates/template_U_112.txt new file mode 100644 index 0000000..841c426 --- /dev/null +++ b/dictation_server/src/templates/template_U_112.txt @@ -0,0 +1,35 @@ + + +Dear $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$ + +Your account information has been edited successfully. To check or change your company's account information, please log in to ODMS Cloud. +URL: $TOP_URL$ + +If you need support regarding ODMS Cloud, please contact $DEALER_NAME$. + +If you have received this e-mail in error, please delete this e-mail from your system. +This is an automatically generated e-mail and this mailbox is not monitored. Please do not reply. + + + +Sehr geehrte(r) $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$ + +Ihre Kontoinformationen wurden erfolgreich bearbeitet. Um die Kontoinformationen Ihres Unternehmens zu überprüfen oder zu ändern, melden Sie sich bitte bei ODMS Cloud an. +URL: $TOP_URL$ + +Wenn Sie Unterstützung bezüglich ODMS Cloud benötigen, wenden Sie sich bitte an $DEALER_NAME$. + +Wenn Sie diese E-Mail fälschlicherweise erhalten haben, löschen Sie diese E-Mail bitte aus Ihrem System. +Dies ist eine automatisch generierte E-Mail und dieses Postfach wird nicht überwacht. Bitte nicht antworten. + + + +Chère/Cher $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$ + +Les informations de votre compte ont été modifiées avec succès. Pour vérifier ou modifier les informations du compte de votre entreprise, veuillez vous connecter à ODMS Cloud. +URL: $TOP_URL$ + +Si vous avez besoin d'assistance concernant ODMS Cloud, veuillez contacter $DEALER_NAME$. + +Si vous avez reçu cet e-mail par erreur, veuillez supprimer cet e-mail de votre système. +Il s'agit d'un e-mail généré automatiquement et cette boîte aux lettres n'est pas surveillée. Merci de ne pas répondre. diff --git a/dictation_server/src/templates/template_U_112_no_parent.html b/dictation_server/src/templates/template_U_112_no_parent.html new file mode 100644 index 0000000..87a7d9d --- /dev/null +++ b/dictation_server/src/templates/template_U_112_no_parent.html @@ -0,0 +1,55 @@ + + + Account Edit Notification [U-112] + + +
+

<English>

+

Dear $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$

+

+ Your account information has been edited successfully. To check or + change your company's account information, please log in to ODMS + Cloud.
+ URL: $TOP_URL$ +

+

+ If you have received this e-mail in error, please delete this e-mail + from your system.
+ This is an automatically generated e-mail and this mailbox is not + monitored. Please do not reply. +

+
+
+

<Deutsch>

+

Sehr geehrte(r) $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$

+

+ Ihre Kontoinformationen wurden erfolgreich bearbeitet. Um die + Kontoinformationen Ihres Unternehmens zu überprüfen oder zu ändern, + melden Sie sich bitte bei ODMS Cloud an.
+ URL: $TOP_URL$ +

+

+ Wenn Sie diese E-Mail fälschlicherweise erhalten haben, löschen Sie + diese E-Mail bitte aus Ihrem System.
+ Dies ist eine automatisch generierte E-Mail und dieses Postfach wird + nicht überwacht. Bitte nicht antworten. +

+
+
+

<Français>

+

Chère/Cher $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$

+

+ Les informations de votre compte ont été modifiées avec succès. Pour + vérifier ou modifier les informations du compte de votre entreprise, + veuillez vous connecter à ODMS Cloud.
+ URL: $TOP_URL$ +

+

+ Si vous avez reçu cet e-mail par erreur, veuillez supprimer cet e-mail + de votre système.
+ Il s'agit d'un e-mail généré automatiquement et cette boîte aux lettres + n'est pas surveillée. Merci de ne pas répondre. +

+
+ + diff --git a/dictation_server/src/templates/template_U_112_no_parent.txt b/dictation_server/src/templates/template_U_112_no_parent.txt new file mode 100644 index 0000000..fc13cb3 --- /dev/null +++ b/dictation_server/src/templates/template_U_112_no_parent.txt @@ -0,0 +1,29 @@ + + +Dear $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$ + +Your account information has been edited successfully. To check or change your company's account information, please log in to ODMS Cloud. +URL: $TOP_URL$ + +If you have received this e-mail in error, please delete this e-mail from your system. +This is an automatically generated e-mail and this mailbox is not monitored. Please do not reply. + + + +Sehr geehrte(r) $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$ + +Ihre Kontoinformationen wurden erfolgreich bearbeitet. Um die Kontoinformationen Ihres Unternehmens zu überprüfen oder zu ändern, melden Sie sich bitte bei ODMS Cloud an. +URL: $TOP_URL$ + +Wenn Sie diese E-Mail fälschlicherweise erhalten haben, löschen Sie diese E-Mail bitte aus Ihrem System. +Dies ist eine automatisch generierte E-Mail und dieses Postfach wird nicht überwacht. Bitte nicht antworten. + + + +Chère/Cher $CUSTOMER_NAME$, -> $PRIMARY_ADMIN_NAME$ + +Les informations de votre compte ont été modifiées avec succès. Pour vérifier ou modifier les informations du compte de votre entreprise, veuillez vous connecter à ODMS Cloud. +URL: $TOP_URL$ + +Si vous avez reçu cet e-mail par erreur, veuillez supprimer cet e-mail de votre système. +Il s'agit d'un e-mail généré automatiquement et cette boîte aux lettres n'est pas surveillée. Merci de ne pas répondre.