update operador
This commit is contained in:
@@ -15,7 +15,7 @@ const login = async (body) => {
|
||||
);
|
||||
|
||||
return Operador.findOne({
|
||||
where: { operador, activo: true },
|
||||
where: { operador },
|
||||
include: [{ model: TipoUsuario }],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
|
||||
@@ -1,8 +1,27 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
|
||||
const update = async (body) => {};
|
||||
const update = async (body) => {
|
||||
const idOperador = validar.validarId(body.idOperador);
|
||||
let update = {};
|
||||
|
||||
if (body.activo === 'desactivar') update.activo = false;
|
||||
if (body.activo === 'activar') update.activo = true;
|
||||
if (body.password)
|
||||
update.password = validar.validarAlfanumerico(
|
||||
body.password,
|
||||
'La Contraseña',
|
||||
20
|
||||
);
|
||||
if (validar.validarObjetoVacio(update))
|
||||
throw new Error('No se mando nada para actualizar.');
|
||||
return Operador.findOne({ where: { idOperador, idTipoUsuario: 2 } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este operador');
|
||||
return Operador.update(update, { where: { idOperador } });
|
||||
})
|
||||
.then((res) => ({ message: 'Se actualizó correctamente al operador.' }));
|
||||
};
|
||||
|
||||
module.exports = update;
|
||||
|
||||
Reference in New Issue
Block a user