Guest User

Untitled

a guest
Jan 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. router.post('/myRoute', (req, res, next) => {
  2. checkParams(req.body).then(paramsResult => {
  3. if(paramsResult.status === 'failed') return res.send(paramsResult);
  4. return checkUserEmail(req.body.email);
  5. }).then(emailResult => {
  6. if(emailResult.status === 'failed') return res.send(emailResult);
  7. return checkPasswordLength(req.body.password);
  8. }).then(passResult => {
  9. if(passResult.status === 'failed') return res.send(passResult);
  10. return ...
  11. }).then(...).catch(err => {
  12. return res.send({ status:'failed', message:'An error occurred.' });
  13. });
  14. });
  15.  
  16. router.post('/myRoute', [checkParams, checkUserEmail, checkPasswordLength, ...], (req, res, next) => {
  17. // I'd set req.user = {...} in the last middleware before this route.
  18. createUser(req.user).then(createResult => {
  19. if(createResult.status === 'failed') return res.send(createResult);
  20. return res.send({ status:'success', message:'Your account has been created.' });
  21. }).catch(err => {
  22. return res.send({ status:'failed', message:'An error occurred.' });
  23. });
  24. });
Add Comment
Please, Sign In to add comment