Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import _ from "lodash"
  2. import { isValidPhone } from "../validation/phone"
  3. import template from "./template"
  4. import { DbConn } from "../Db"
  5. import SmsService from "../SmsService"
  6.  
  7. const createMessage = _.template(template)
  8.  
  9. export const sendSms = userId => {
  10. const service = new SmsService()
  11.  
  12. return DbConn.User.byId(userId)
  13. .then(throwIfInvalidPhone)
  14. .then(createMessage)
  15. .then(message => service.send(message, user.phone))
  16. .then(() => ([ userId, message ]))
  17. }
  18.  
  19. const throwIfInvalidPhone = user => {
  20. if (!isValidPhone(user.phone)) {
  21. throw new Error(`Invalid phone for user ${ userId }.`);
  22. }
  23.  
  24. return user
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement