Files
pcpuma_acatlan_api/server/controller/Equipo/equipos.js
T

36 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-04-29 19:43:33 -05:00
const validar = require('../../helper/validar');
2021-05-03 23:38:03 -05:00
const dbPath = '../../db/tablas';
const Carrito = require(`${dbPath}/Carrito`);
const Equipo = require(`${dbPath}/Equipo`);
const Modulo = require(`${dbPath}/Modulo`);
const Programa = require(`${dbPath}/Programa`);
const Status = require(`${dbPath}/Status`);
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
2021-04-29 19:43:33 -05:00
2021-05-04 00:32:04 -05:00
const equipos = 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 Equipo.findAndCountAll({
2021-04-29 19:43:33 -05:00
include: [
{ model: Carrito, include: [{ model: TipoCarrito }, { model: Modulo }] },
{ model: Status },
{ model: Programa },
],
2021-04-30 16:04:27 -05:00
limit: 25,
offset: 25 * (pagina - 1),
2021-04-29 19:43:33 -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.idCarrito;
delete res.rows[i].dataValues.idPrograma;
delete res.rows[i].dataValues.idStatus;
delete res.rows[i].dataValues.Carrito.dataValues.idTipoCarrito;
delete res.rows[i].dataValues.Carrito.dataValues.idModulo;
if (!res.rows[i].Programa) delete res.rows[i].dataValues.Programa;
2021-04-29 19:43:33 -05:00
}
2021-05-04 00:32:04 -05:00
return { count: res.count, equipos: res.rows };
2021-04-29 19:43:33 -05:00
});
};
2021-05-04 00:32:04 -05:00
module.exports = equipos;