update operador

This commit is contained in:
Lemuel Marquez
2021-05-26 15:47:24 -05:00
parent 5a2a722470
commit a50863ab29
5 changed files with 43 additions and 10 deletions
+1 -1
View File
@@ -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.');
+21 -2
View File
@@ -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;