diff --git a/src/EmailService.ts b/src/EmailService.ts index 6ee8563..01dd424 100644 --- a/src/EmailService.ts +++ b/src/EmailService.ts @@ -4,6 +4,8 @@ import fs from 'fs' import twig from 'twig' export default class EmailService { + static transporter: any = null + static init() { if (this.isMocked()) { console.warn('> EmailService: WARNING: EMAIL IS MOCKED!') @@ -25,7 +27,7 @@ export default class EmailService { pass: process.env.SMTP_PASSWORD, } } - //console.log(config) + console.log('> EmailService: Transport created ', config) return nodemailer.createTransport(config) } @@ -43,7 +45,10 @@ export default class EmailService { // text: params.text, // html: params.html // }) - return this.getTransporter().sendMail(params) + if (EmailService.transporter === null) { + EmailService.transporter = EmailService.getTransporter() + } + return EmailService.transporter.sendMail(params) } static send(to: string, subject: string, templateName: string, templateParams: any): Promise { @@ -72,10 +77,10 @@ export default class EmailService { resolve() } else { this.nativeSend(config).then(res => { - console.log('> A "' + templateName + '" email was sent') + console.log('> A "' + templateName + '" email was sent to ' + to) resolve(res) }).catch(err => { - console.log('> A "' + templateName + '" email failed to be sent') + console.log('> A "' + templateName + '" email failed to be sent to ' + to) console.error(err) reject() }) diff --git a/src/controllers/AdminOrganizationController.ts b/src/controllers/AdminOrganizationController.ts index abefe0b..aec8b6d 100644 --- a/src/controllers/AdminOrganizationController.ts +++ b/src/controllers/AdminOrganizationController.ts @@ -72,7 +72,7 @@ export default class AdminOrganizationController { } static storeUniversal(adminName: string, email: string, validationState: string): Promise { - console.log(adminName, email, validationState) + console.log('> AdminOrganizationController: STORE:', adminName, email, validationState) return new Promise((resolve, reject) => { if (validationState == null) { validationState = 'unaware' @@ -111,7 +111,7 @@ export default class AdminOrganizationController { } } Organization.create(body).then(data => { - //AdminOrganizationController.sendEmailTokenUniversal(data) + AdminOrganizationController.sendEmailTokenUniversal(data) resolve({ data, body }) }).catch(err => reject(err)) }) diff --git a/src/models/Organization.ts b/src/models/Organization.ts index d406d2b..3ee658a 100644 --- a/src/models/Organization.ts +++ b/src/models/Organization.ts @@ -29,10 +29,7 @@ class AllowedString extends mongoose.SchemaType { const email = { type: String, validate: { - validator: function(v: string) { - console.log(v) - return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(v); - }, + validator: (v: string) => /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(v), message: "Invalid email" } }