const validar = require('../../helper/validar'); const dbPath = '../../db/tablas'; const Reporte = require(`${dbPath}/Reporte`); const Operador = require(`${dbPath}/Operador`); const Prestamo = require(`${dbPath}/Prestamo`); const Usuario = require(`${dbPath}/Usuario`); const historialReportes = async (body) => { const idEquipo = validar.validarId(body.idEquipo); const pagina = validar.validarNumero(body.pagina, true); return Reporte.findAndCountAll({ where: { idEquipo }, include: [ { model: Prestamo, include: [ { model: Usuario }, { model: Operador, as: 'OperadorRegreso' }, ], }, { model: Operador }, ], limit: 25, offset: 25 * (pagina - 1), order: [['createdAt', 'DESC']], }).then((res) => { for (let i = 0; i < res.rows.length; i++) { delete res.rows[i].dataValues.idPrestamo; delete res.rows[i].dataValues.idEquipo; delete res.rows[i].dataValues.idOperador; if (res.rows[i].dataValues.Prestamo) { delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorEntrega; delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorRegreso; delete res.rows[i].dataValues.Prestamo.dataValues.idUsuario; delete res.rows[i].dataValues.Prestamo.dataValues.idEquipo; delete res.rows[i].dataValues.Prestamo.dataValues.Usuario.dataValues .password; delete res.rows[i].dataValues.Prestamo.dataValues.Usuario.dataValues .idCarrera; delete res.rows[i].dataValues.Prestamo.dataValues.Usuario.dataValues .idTipoUsuario; delete res.rows[i].dataValues.Prestamo.dataValues.OperadorRegreso .dataValues.idTipoUsuario; delete res.rows[i].dataValues.Prestamo.dataValues.OperadorRegreso .dataValues.password; delete res.rows[i].dataValues.Operador; } if (res.rows[i].dataValues.Operador) { delete res.rows[i].dataValues.Operador.dataValues.password; delete res.rows[i].dataValues.Operador.dataValues.idTipoUsuario; delete res.rows[i].dataValues.Operador.dataValues.activo; delete res.rows[i].dataValues.Prestamo; } } return { count: res.count, historialReportes: res.rows }; }); }; module.exports = historialReportes;