mini cambios#
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const { Op } = require('sequelize');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
@@ -12,15 +13,17 @@ const operadores = async (body) => {
|
||||
true,
|
||||
true
|
||||
);
|
||||
// filtros
|
||||
const operador = body.operador
|
||||
? validar.validarTexto(body.operador, 'operador', true, 20)
|
||||
: '';
|
||||
|
||||
return Operador.findAndCountAll({
|
||||
where: { idTipoUsuario: 2 },
|
||||
where: { idTipoUsuario: 2, operador: { [Op.like]: `%${operador}%` } },
|
||||
include: [{ model: TipoUsuario }],
|
||||
attributes: ['idOperador', 'operador', 'activo'],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
}).then((res) => ({ count: res.count, operadores: res.rows }));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = operadores;
|
||||
|
||||
@@ -9,19 +9,19 @@ const update = async (body) => {
|
||||
'id operador',
|
||||
true
|
||||
);
|
||||
const password = body.password
|
||||
? validar.validarAlfanumerico(body.password, 'contraseña', false, 20)
|
||||
: '';
|
||||
let update = {};
|
||||
|
||||
if (body.activo === 'desactivar') update.activo = false;
|
||||
else if (body.activo === 'activar') update.activo = true;
|
||||
if (body.password)
|
||||
update.password = encriptar(
|
||||
validar.validarAlfanumerico(body.password, 'contraseña', false, 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.');
|
||||
if (body.activo === 'desactivar') update.activo = false;
|
||||
else if (body.activo === 'activar') update.activo = true;
|
||||
if (password) update.password = encriptar(password);
|
||||
if (validar.validarObjetoVacio(update))
|
||||
throw new Error('No se mando nada para actualizar.');
|
||||
return Operador.update(update, { where: { idOperador } });
|
||||
})
|
||||
.then((res) => ({ message: 'Se actualizó correctamente al operador.' }));
|
||||
|
||||
Reference in New Issue
Block a user