Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- register(req, res) {
- // ...
- indicative.validateAll(req.body.data, rules)
- .then(
- () => {
- const data = {
- ...req.body.data,
- password: bcrypt.hashSync(req.body.data.password, bcrypt.genSaltSync()),
- password_confirmation: undefined,
- customer: {}
- };
- return models.User.query()
- .insertGraph(data);
- }
- )
- .catch( // catch block 1
- (error) => {
- console.log(error);
- return response.error(res, 422, 'Dados de cadastro inválidos.');
- }
- )
- .then(
- (user) => {
- return response.success(res, 'Usuário cadastrado com sucesso.', {
- user: user
- });
- }
- )
- .catch( // catch block 2
- (error) => {
- console.log(error);
- return response.error(res, 500, 'Erro interno, tente novamente.');
- }
- );
- }
Add Comment
Please, Sign In to add comment