Skip to content

Instantly share code, notes, and snippets.

@Technoash
Created March 1, 2016 19:26
Show Gist options
  • Select an option

  • Save Technoash/685dde7298b0bbfe7328 to your computer and use it in GitHub Desktop.

Select an option

Save Technoash/685dde7298b0bbfe7328 to your computer and use it in GitHub Desktop.
validateRegister(req.body)
.then(function(errors){
if(errors.count > 0){
res.send({state: 'failure', registerFormErrors: errors.messages, errorCount: errors.count});
return;
}
//this won't always happen
return db.createUser(req.body.name, req.body.email, req.body.password);
})
.then(function(newUser){
//what if createUser wasn't added to the chain?
res.send({state: 'success', name: newUser.name});
})
.catch(function(err){
res.send(500);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment