@lomray/microservice-users
Version:
Users microservice based on NodeJS & inverted json.
46 lines (42 loc) • 1.33 kB
JavaScript
;
var tslib = require('tslib');
var microserviceHelpers = require('@lomray/microservice-helpers');
var abstract = require('./abstract.js');
/**
* Email confirmation service
*/
class Email extends abstract {
/**
* @inheritDoc
*/
send(email) {
return tslib.__awaiter(this, void 0, void 0, function* () {
const code = this.generateCode();
const [isSuccess] = yield Promise.all([
Email.sendEmail(email, code),
this.saveCode(email, code),
]);
return isSuccess;
});
}
/**
* Send email with confirm code
* @protected
*/
static sendEmail(email, code) {
return tslib.__awaiter(this, void 0, void 0, function* () {
const { error } = yield microserviceHelpers.Api.get().notification.email.send({
to: [email],
subject: 'Email confirmation code.',
text: `Your confirmation code is: ${code}`,
html: `<p>Your confirmation code is: <strong>${code}</strong></p>`,
});
if (!error) {
return true;
}
microserviceHelpers.Log.error('Failed send confirmation email', error);
return false;
});
}
}
module.exports = Email;