Files
pcpuma_acatlan_api/server/controller/Usuario/usuarios.js
T

29 lines
939 B
JavaScript
Raw Normal View History

const { Op } = require('sequelize');
2021-04-28 00:21:24 -05:00
const validar = require('../../helper/validar');
2021-05-03 23:38:03 -05:00
const dbPath = '../../db/tablas';
const Usuario = require(`${dbPath}/Usuario`);
const Carrera = require(`${dbPath}/Carrera`);
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
2021-04-28 00:21:24 -05:00
2021-05-04 00:32:04 -05:00
const usuarios = async (body) => {
2021-05-18 22:40:30 -05:00
const pagina = validar.validarNumero(body.pagina, true);
// filtros
2021-04-30 16:04:27 -05:00
return Usuario.findAndCountAll({
where: { password: { [Op.ne]: null } },
2021-04-28 00:21:24 -05:00
include: [{ model: TipoUsuario }, { model: Carrera }],
2021-04-30 16:04:27 -05:00
limit: 25,
offset: 25 * (pagina - 1),
2021-04-28 00:21:24 -05:00
}).then((res) => {
2021-04-30 16:04:27 -05:00
for (let i = 0; i < res.rows.length; i++) {
delete res.rows[i].dataValues.password;
delete res.rows[i].dataValues.idTipoUsuario;
delete res.rows[i].dataValues.idCarrera;
if (!res.rows[i].Carrera) delete res.rows[i].dataValues.Carrera;
2021-04-29 19:26:39 -05:00
}
2021-05-04 00:32:04 -05:00
return { count: res.count, usuarios: res.rows };
2021-04-28 00:21:24 -05:00
});
};
2021-05-04 00:32:04 -05:00
module.exports = usuarios;