-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add isolated email templates and template builder
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
api/src/modules/notifications/email/templates/email-template.builder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { WELCOME_EMAIL_HTML_CONTENT } from '@api/modules/notifications/email/templates/welcome-email.template'; | ||
import { RESET_PASSWORD_HTML_CONTENT } from '@api/modules/notifications/email/templates/reset-password.template'; | ||
import { EMAIL_UPDATE_CONFIRMATION_HTML_CONTENT } from '@api/modules/notifications/email/templates/email-update-confirmation.template'; | ||
|
||
export enum TEMPLATE_TYPE { | ||
WELCOME = 'welcome', | ||
RESET_PASSWORD = 'reset-password', | ||
EMAIL_UPDATE_CONFIRMATION = 'email-update-confirmation', | ||
} | ||
|
||
export interface TemplateConfig { | ||
url: string; | ||
expiration: number; | ||
type: TEMPLATE_TYPE; | ||
} | ||
|
||
export class EmailTemplateBuilder { | ||
url: string; | ||
expiration: number; | ||
type: TEMPLATE_TYPE; | ||
templateMap = { | ||
WELCOME_EMAIL_HTML_CONTENT: WELCOME_EMAIL_HTML_CONTENT, | ||
RESET_PASSWORD_HTML_CONTENT: RESET_PASSWORD_HTML_CONTENT, | ||
EMAIL_UPDATE_CONFIRMATION_HTML_CONTENT: | ||
EMAIL_UPDATE_CONFIRMATION_HTML_CONTENT, | ||
}; | ||
constructor(contentConfig: TemplateConfig) { | ||
this.url = contentConfig.url; | ||
this.expiration = contentConfig.expiration; | ||
this.type = contentConfig.type; | ||
} | ||
|
||
build() { | ||
const template = this.templateMap[this.type]; | ||
return template(this.url, this.expiration); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
api/src/modules/notifications/email/templates/email-update-confirmation.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const EMAIL_UPDATE_CONFIRMATION_HTML_CONTENT = ( | ||
url, | ||
expiration, | ||
): string => ` | ||
<h1>Dear User,</h1> | ||
<br/> | ||
<p>We have received a request to change the email address associated with your account. If you initiated this request, please confirm the change by clicking the link below:</p> | ||
<br/> | ||
<p><a href="${url}" target="_blank" rel="noopener noreferrer">Confirm Email Change</a></p> | ||
<br/> | ||
<p>This link will redirect you to our app to confirm the new email address. For security reasons, this link will expire in ${expiration}.</p> | ||
<p>If you did not request this email change, please ignore this message; your account information will remain unchanged.</p> | ||
<br/> | ||
<p>Thank you for using our platform. We value your security and account privacy.</p> | ||
<p>Best regards.</p>`; |
15 changes: 15 additions & 0 deletions
15
api/src/modules/notifications/email/templates/reset-password.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const RESET_PASSWORD_HTML_CONTENT = ( | ||
url: string, | ||
expiration: number, | ||
): string => ` | ||
<h1>Dear User,</h1> | ||
<br/> | ||
<p>We recently received a request to reset your password for your account. If you made this request, please click on the link below to securely change your password:</p> | ||
<br/> | ||
<p><a href="${url}" target="_blank" rel="noopener noreferrer">Secure Password Reset Link</a></p> | ||
<br/> | ||
<p>This link will direct you to our app to create a new password. For security reasons, this link will expire after ${expiration}.</p> | ||
<p>If you did not request a password reset, please ignore this email; your password will remain the same.</p> | ||
<br/> | ||
<p>Thank you for using the platform. We're committed to ensuring your account's security.</p> | ||
<p>Best regards.</p>`; |
12 changes: 12 additions & 0 deletions
12
api/src/modules/notifications/email/templates/welcome-email.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const WELCOME_EMAIL_HTML_CONTENT = (url, expiration): string => ` | ||
<h1>Dear User,</h1> | ||
<br/> | ||
<p>We recently received a request to reset your password for your account. If you made this request, please click on the link below to securely change your password:</p> | ||
<br/> | ||
<p><a href="${url}" target="_blank" rel="noopener noreferrer">Secure Password Reset Link</a></p> | ||
<br/> | ||
<p>This link will direct you to our app to create a new password. For security reasons, this link will expire after ${expiration}.</p> | ||
<p>If you did not request a password reset, please ignore this email; your password will remain the same.</p> | ||
<br/> | ||
<p>Thank you for using the platform. We're committed to ensuring your account's security.</p> | ||
<p>Best regards.</p>`; |