Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import _ from "lodash"
- import { isValidPhone } from "../validation/phone"
- import template from "./template"
- import { DbConn } from "../Db"
- import SmsService from "../SmsService"
- const createMessage = _.template(template)
- export const sendSms = userId => {
- const service = new SmsService()
- return DbConn.User.byId(userId)
- .then(throwIfInvalidPhone)
- .then(createMessage)
- .then(message => service.send(message, user.phone))
- .then(() => ([ userId, message ]))
- }
- const throwIfInvalidPhone = user => {
- if (!isValidPhone(user.phone)) {
- throw new Error(`Invalid phone for user ${ userId }.`);
- }
- return user
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement