UNPKG

@lomray/microservice-users

Version:

Users microservice based on NodeJS & inverted json.

44 lines (40 loc) 1.18 kB
'use strict'; var tslib = require('tslib'); var microserviceHelpers = require('@lomray/microservice-helpers'); var abstract = require('./abstract.js'); /** * Phone confirmation service */ class Phone extends abstract { /** * @inheritDoc */ send(phone) { return tslib.__awaiter(this, void 0, void 0, function* () { const code = this.generateCode(); const [isSuccess] = yield Promise.all([ Phone.sendCode(phone, code), this.saveCode(phone, code), ]); return isSuccess; }); } /** * Send sms with confirm code * @private */ static sendCode(phone, code) { return tslib.__awaiter(this, void 0, void 0, function* () { const { error } = yield microserviceHelpers.Api.get().notification.phone.send({ to: [phone], message: `Confirmation code is: ${code}`, }); if (!error) { return true; } microserviceHelpers.Log.error('Failed send confirmation phone', error); return false; }); } } module.exports = Phone;