bulletproof-nodejs
bulletproof-nodejs copied to clipboard
SendWelcomeEmail is not async
Maybe it's not very important, but I understand that even if SendWelcomeEmail()
is declared as an async function
https://github.com/santiq/bulletproof-nodejs/blob/ee0e80dfba34f7e9b658a4ca4cedf1dd6970511d/src/services/mailer.ts#L10
in reality it's not:
https://github.com/santiq/bulletproof-nodejs/blob/ee0e80dfba34f7e9b658a4ca4cedf1dd6970511d/src/services/mailer.ts#L22-L23
In order to be async, and effectively return only when the email has been set (or in case of error), we would require something like:
return new Promise((resolve, reject) => this.emailClient.messages().send(data, function (error, body) {
if (error) {
reject ({ delivered: 0, status: 'error', error });
} else {
resolve ({ delivered: 1, status: 'ok' });
}
});