diff --git a/dictation_server/src/features/users/users.service.ts b/dictation_server/src/features/users/users.service.ts index 359f163..6b58912 100644 --- a/dictation_server/src/features/users/users.service.ts +++ b/dictation_server/src/features/users/users.service.ts @@ -1073,13 +1073,13 @@ export class UsersService { const { parent_account_id: dealerId } = await this.accountsRepository.findAccountById(context, accountId); - if (dealerId == null) { - throw new Error(`dealer is null. account_id=${accountId}`); + let dealerName: string | null = null; + if (dealerId !== null) { + const { company_name } = + await this.accountsRepository.findAccountById(context, dealerId); + dealerName = company_name; } - const { company_name: dealerName } = - await this.accountsRepository.findAccountById(context, dealerId); - const { companyName, adminEmails } = await this.getAccountInformation( context, accountId, diff --git a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts index 985c7b1..17fa39b 100644 --- a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts +++ b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts @@ -41,6 +41,9 @@ export class SendGridService { private readonly templateU107Text: string; private readonly templateU108Html: string; private readonly templateU108Text: string; + // U-108のテンプレート差分(親アカウントがない場合) + private readonly templateU108NoParentHtml: string; + private readonly templateU108NoParentText: string; private readonly templateU109Html: string; private readonly templateU109Text: string; private readonly templateU111Html: string; @@ -118,6 +121,17 @@ export class SendGridService { path.resolve(__dirname, `../../templates/template_U_108.txt`), 'utf-8', ); + this.templateU108NoParentHtml = readFileSync( + path.resolve( + __dirname, + `../../templates/template_U_108_no_parent.html`, + ), + 'utf-8', + ); + this.templateU108NoParentText = readFileSync( + path.resolve(__dirname, `../../templates/template_U_108_no_parent.txt`), + 'utf-8', + ); this.templateU109Html = readFileSync( path.resolve(__dirname, `../../templates/template_U_109.html`), 'utf-8', @@ -462,7 +476,7 @@ export class SendGridService { userMail: string, customerAdminMails: string[], customerAccountName: string, - dealerAccountName: string, + dealerAccountName: string | null, ): Promise { this.logger.log( `[IN] [${context.getTrackingId()}] ${this.sendMailWithU108.name}`, @@ -471,19 +485,34 @@ export class SendGridService { const subject = 'License Assigned Notification [U-108]'; const url = new URL(this.appDomain).href; - // メールの本文を作成する - const html = this.templateU108Html - .replaceAll(CUSTOMER_NAME, customerAccountName) - .replaceAll(DEALER_NAME, dealerAccountName) - .replaceAll(USER_NAME, userName) - .replaceAll(USER_EMAIL, userMail) - .replaceAll(TOP_URL, url); - const text = this.templateU108Text - .replaceAll(CUSTOMER_NAME, customerAccountName) - .replaceAll(DEALER_NAME, dealerAccountName) - .replaceAll(USER_NAME, userName) - .replaceAll(USER_EMAIL, userMail) - .replaceAll(TOP_URL, url); + let html: string; + let text: string; + + if (dealerAccountName === null) { + html = this.templateU108NoParentHtml + .replaceAll(CUSTOMER_NAME, customerAccountName) + .replaceAll(USER_NAME, userName) + .replaceAll(USER_EMAIL, userMail) + .replaceAll(TOP_URL, url); + text = this.templateU108NoParentText + .replaceAll(CUSTOMER_NAME, customerAccountName) + .replaceAll(USER_NAME, userName) + .replaceAll(USER_EMAIL, userMail) + .replaceAll(TOP_URL, url); + } else { + html = this.templateU108Html + .replaceAll(CUSTOMER_NAME, customerAccountName) + .replaceAll(DEALER_NAME, dealerAccountName) + .replaceAll(USER_NAME, userName) + .replaceAll(USER_EMAIL, userMail) + .replaceAll(TOP_URL, url); + text = this.templateU108Text + .replaceAll(CUSTOMER_NAME, customerAccountName) + .replaceAll(DEALER_NAME, dealerAccountName) + .replaceAll(USER_NAME, userName) + .replaceAll(USER_EMAIL, userMail) + .replaceAll(TOP_URL, url); + } const ccAddress = customerAdminMails.includes(userMail) ? [] : [userMail]; diff --git a/dictation_server/src/templates/template_U_108_no_parent.html b/dictation_server/src/templates/template_U_108_no_parent.html new file mode 100644 index 0000000..b8b6b8b --- /dev/null +++ b/dictation_server/src/templates/template_U_108_no_parent.html @@ -0,0 +1,69 @@ + + + License Assigned Notification [U-108] + + +
+

<English>

+

Dear $CUSTOMER_NAME$,

+

+ Please be informed that a license has been assigned to the following + user.
+ - User Name: $USER_NAME$
+ - Email: $USER_EMAIL$ +

+

+ Please log in to ODMS Cloud to verify the license expiration date.
+ 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$,

+

+ Bitte beachten Sie, dass dem folgenden Benutzer eine Lizenz zugewiesen + wurde.
+ - Nutzername: $USER_NAME$
+ - Email: $USER_EMAIL$ +

+

+ Bitte melden Sie sich bei ODMS Cloud an, um das Ablaufdatum der Lizenz + zu überprüfen.
+ 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$,

+

+ Veuillez être informé qu'une licence a été attribuée à l'utilisateur + suivant.
+ - Nom d'utilisateur: $USER_NAME$
+ - Email: $USER_EMAIL$ +

+

+ Veuillez vous connecter à ODMS Cloud pour vérifier la date d'expiration + de la licence.
+ 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_108_no_parent.txt b/dictation_server/src/templates/template_U_108_no_parent.txt new file mode 100644 index 0000000..b0ce4a2 --- /dev/null +++ b/dictation_server/src/templates/template_U_108_no_parent.txt @@ -0,0 +1,41 @@ + + +Dear $CUSTOMER_NAME$, + +Please be informed that a license has been assigned to the following user. + - User Name: $USER_NAME$ + - Email: $USER_EMAIL$ + +Please log in to ODMS Cloud to verify the license expiration date. +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$, + +Bitte beachten Sie, dass dem folgenden Benutzer eine Lizenz zugewiesen wurde. + - Nutzername: $USER_NAME$ + - Email: $USER_EMAIL$ + +Bitte melden Sie sich bei ODMS Cloud an, um das Ablaufdatum der Lizenz zu überprüfen. +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$, + +Veuillez être informé qu'une licence a été attribuée à l'utilisateur suivant. + - Nom d'utilisateur: $USER_NAME$ + - Email: $USER_EMAIL$ + +Veuillez vous connecter à ODMS Cloud pour vérifier la date d'expiration de la licence. +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. \ No newline at end of file