Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. const email = req.body.email;
  2. const password = req.body.password;
  3. const query = UserModel.findOne({ email });
  4.  
  5. query.exec()
  6. .then((existingUser) => {
  7. if (existingUser) {
  8. logger.info('user found');
  9. return res.status(422).send({ error: 'Email in use' });
  10. }
  11.  
  12. const user = new UserModel({
  13. email,
  14. password
  15. });
  16.  
  17. return user.save()
  18. .then(() => {
  19. res.send({ error: false });
  20. })
  21. ;
  22. })
  23. .catch((err) => {
  24. logger.error(err);
  25. if (err.name === 'ValidationError') {
  26. return res.status(422).send(
  27. { error: `You must provide: ${Object.keys(err.errors).join(', ')}` }
  28. );
  29. }
  30.  
  31. return res.send({ error: true });
  32. })
  33. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement