This commit is contained in:
2020-10-02 11:55:27 -05:00
parent 2a6108d809
commit 3e7907d083
5 changed files with 69 additions and 2 deletions
+22
View File
@@ -0,0 +1,22 @@
require('../../config/config')
const bcrypt = require('bcrypt')
const Operador = require('../../db/tables/Operador')
const create = (body) => {
return Operador.create({
nombre: body.nombre,
password: bcrypt.hashSync(body.password, Number(process.env.SALT_ROUNDS)),
idTipoOperador: 2,
})
.then((res) => {
console.log(res)
return { mensaje: 'Se creo un operador correctamente' }
})
.catch((err) => {
throw new Error(err)
})
}
module.exports = create
// create({ nombre: 'Lemuel', password: 'hola' })
+4 -1
View File
@@ -5,8 +5,9 @@ const login = (body) => {
return Operador.findOne({ where: { nombre: body.nombre } })
.then((res) => {
if (res) {
if (!bcrypt.compareSync(body.password, res.password))
if (!bcrypt.compareSync(body.password, res.password)) {
throw new Error('El usuario o contraseña son incorrectos.')
}
return { res }
}
throw new Error('El usuario o contraseña son incorrectos.')
@@ -15,3 +16,5 @@ const login = (body) => {
}
module.exports = login
// login({ nombre: 'lemuel', password: 'hola' })