-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
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,38 @@ | ||
import path from 'path' | ||
import handlebars from 'handlebars' | ||
import { readHTMLFile } from 'helpers/Common' | ||
import EmailProvider from 'config/email' | ||
import ResponseError from 'modules/Response/ResponseError' | ||
import { BASE_URL_CLIENT } from 'config/baseClient' | ||
import { EmailAttributes, UserAttributes } from 'models/user' | ||
|
||
class SendMail { | ||
/** | ||
* | ||
* @param formData | ||
* @param token | ||
*/ | ||
public static AccountRegister(formData: UserAttributes, token: string) { | ||
const { email, fullName }: EmailAttributes = formData | ||
const pathTemplate = path.resolve( | ||
__dirname, | ||
`../../public/templates/emails/register.html` | ||
) | ||
const subject = 'Verifikasi Email' | ||
const urlToken = `${BASE_URL_CLIENT}/email/verify?token=${token}` | ||
const dataTemplate = { fullName, urlToken } | ||
const Email = new EmailProvider() | ||
|
||
readHTMLFile(pathTemplate, (error: Error, html: any) => { | ||
if (error) { | ||
throw new ResponseError.NotFound('email template not found') | ||
} | ||
|
||
const template = handlebars.compile(html) | ||
const htmlToSend = template(dataTemplate) | ||
Email.send(email, subject, htmlToSend) | ||
}) | ||
} | ||
} | ||
|
||
export default SendMail |