36 lines
927 B
JavaScript
36 lines
927 B
JavaScript
const { Op } = require('sequelize');
|
|
const validar = require('../../helper/validar');
|
|
const Usuario = require('../../db/tablas/Usuario');
|
|
|
|
const responsables = async (body) => {
|
|
const pagina = validar.validarNumero(
|
|
body.pagina,
|
|
'página',
|
|
false,
|
|
null,
|
|
true,
|
|
true
|
|
);
|
|
const nombre = body.nombre
|
|
? validar.validarTexto(body.nombre, 'nombre', true, 60)
|
|
: '';
|
|
const correo = body.correo
|
|
? validar.validacionBasicaStr(body.correo, 'correo', true, 1000)
|
|
: '';
|
|
|
|
return Usuario.findAndCountAll({
|
|
where: {
|
|
[Op.and]: [
|
|
{ usuario: { [Op.like]: `%${correo}%` } },
|
|
{ nombre: { [Op.like]: `%${nombre}%` } },
|
|
{ idTipoUsuario: 2 },
|
|
],
|
|
},
|
|
attributes: ['idUsuario', 'usuario', 'nombre', 'activo'],
|
|
limit: 25,
|
|
offset: 25 * (pagina - 1),
|
|
}).then((res) => ({ count: res.count, responsables: res.rows }));
|
|
};
|
|
|
|
module.exports = responsables;
|