Skip to content

Instantly share code, notes, and snippets.

@robotlolita

robotlolita/.js Secret

Last active September 9, 2015 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robotlolita/7396b1e4f59c37855761 to your computer and use it in GitHub Desktop.
Save robotlolita/7396b1e4f59c37855761 to your computer and use it in GitHub Desktop.
function parse(body) {
return body.phoneNumber? validate(formatCountry(body.phoneNumber)).map(aggregate({ source: 'website' }))
: body.From? validate(formatCountry(body.From)).map(aggregate({ source: 'cookie' }))
: /* otherwise */ Failure({ status: 522, message: 'Please enter a valid US number!' })
}
// This returns a promise with the result
export function create(req) {
return parse(req.body)
.toPromise()
.then(function({ number, source }) {
return { data: Pre.findOrCreate({phoneNumber, source}) };
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment