Last active
December 3, 2017 15:50
-
-
Save viniazvd/b9913338cebe494e2df2f3c1c3dbb7f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
signup: async (name, email, password) => { | |
try { | |
const foundUser = await models.user.findOne({ where: { email } }) | |
if (foundUser) { | |
return ({ error: 'E-mail já existe. Tente se registrar com outro.' }) | |
// return Promise.reject(new Error('E-mail já existe. Tente se registrar com outro.')) | |
} | |
const passwordEncrypted = await hashing(password) | |
const newUser = await models.user.build({ name, email, password: passwordEncrypted }) | |
await newUser.save() | |
return Promise.resolve({ user: newUser }) | |
} catch (error) { | |
// return Promise.reject(error) | |
errorHandler(error, 'Erro ao registrar usuário', Promise.reject) | |
} | |
}, | |
... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment