File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ import path from 'path'
2+ import handlebars from 'handlebars'
3+ import { readHTMLFile } from 'helpers/Common'
4+ import EmailProvider from 'config/email'
5+ import ResponseError from 'modules/Response/ResponseError'
6+ import { BASE_URL_CLIENT } from 'config/baseClient'
7+ import { EmailAttributes , UserAttributes } from 'models/user'
8+
9+ class SendMail {
10+ /**
11+ *
12+ * @param formData
13+ * @param token
14+ */
15+ public static AccountRegister ( formData : UserAttributes , token : string ) {
16+ const { email, fullName } : EmailAttributes = formData
17+ const pathTemplate = path . resolve (
18+ __dirname ,
19+ `../../public/templates/emails/register.html`
20+ )
21+ const subject = 'Verifikasi Email'
22+ const urlToken = `${ BASE_URL_CLIENT } /email/verify?token=${ token } `
23+ const dataTemplate = { fullName, urlToken }
24+ const Email = new EmailProvider ( )
25+
26+ readHTMLFile ( pathTemplate , ( error : Error , html : any ) => {
27+ if ( error ) {
28+ throw new ResponseError . NotFound ( 'email template not found' )
29+ }
30+
31+ const template = handlebars . compile ( html )
32+ const htmlToSend = template ( dataTemplate )
33+ Email . send ( email , subject , htmlToSend )
34+ } )
35+ }
36+ }
37+
38+ export default SendMail
You can’t perform that action at this time.
0 commit comments