Guest User

Untitled

a guest
Oct 5th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. register(req, res) {
  2. // ...
  3. indicative.validateAll(req.body.data, rules)
  4. .then(
  5. () => {
  6. const data = {
  7. ...req.body.data,
  8. password: bcrypt.hashSync(req.body.data.password, bcrypt.genSaltSync()),
  9. password_confirmation: undefined,
  10. customer: {}
  11. };
  12. return models.User.query()
  13. .insertGraph(data);
  14. }
  15. )
  16. .catch( // catch block 1
  17. (error) => {
  18. console.log(error);
  19. return response.error(res, 422, 'Dados de cadastro inválidos.');
  20. }
  21. )
  22. .then(
  23. (user) => {
  24. return response.success(res, 'Usuário cadastrado com sucesso.', {
  25. user: user
  26. });
  27. }
  28. )
  29. .catch( // catch block 2
  30. (error) => {
  31. console.log(error);
  32. return response.error(res, 500, 'Erro interno, tente novamente.');
  33. }
  34. );
  35. }
Add Comment
Please, Sign In to add comment