Files

41 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2020-11-19 12:23:39 -06:00
const { Op } = require('sequelize');
const validar = require('../../helper/validar');
2021-05-14 19:31:12 -05:00
const Usuario = require('../../db/tablas/Usuario');
2020-11-19 12:23:39 -06:00
2021-05-05 19:16:15 -05:00
const responsables = async (body) => {
2022-01-02 18:25:31 -06:00
const pagina = validar.validarNumero(
body.pagina,
'página',
false,
null,
true,
true
);
2021-01-14 03:13:37 -06:00
const nombre = body.nombre
2022-01-02 15:27:30 -06:00
? validar.validarTexto(body.nombre, 'nombre', true, 60)
2020-11-27 12:36:53 -06:00
: '';
2021-01-14 03:13:37 -06:00
const correo = body.correo
2022-01-02 18:36:46 -06:00
? validar.validacionBasicaStr(body.correo, 'correo', true, 1000)
2020-11-19 12:23:39 -06:00
: '';
2021-05-05 19:16:15 -05:00
return Usuario.findAndCountAll({
2020-12-08 21:32:58 -06:00
where: {
2021-06-08 22:01:14 -05:00
[Op.and]: [
{ usuario: { [Op.like]: `%${correo}%` } },
{ nombre: { [Op.like]: `%${nombre}%` } },
{ idTipoUsuario: 2 },
],
2020-12-08 21:32:58 -06:00
},
2021-05-05 19:16:15 -05:00
limit: 25,
offset: 25 * (pagina - 1),
2020-12-08 21:32:58 -06:00
}).then((res) => {
2021-05-05 19:16:15 -05:00
for (let i = 0; i < res.rows.length; i++) {
2021-05-12 21:05:53 -05:00
delete res.rows[i].dataValues.password;
delete res.rows[i].dataValues.idTipoUsuario;
2021-01-14 03:13:37 -06:00
}
2021-05-05 19:16:15 -05:00
return { count: res.count, responsables: res.rows };
2020-12-08 21:32:58 -06:00
});
2020-11-19 12:23:39 -06:00
};
2021-05-05 19:16:15 -05:00
module.exports = responsables;