36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
const validar = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const Multa = require(`${dbPath}/Multa`);
|
|
const Infraccion = require(`${dbPath}/Infraccion`);
|
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
|
|
|
const historialMultas = async (body) => {
|
|
const idUsuario = validar.validarId(body.idUsuario);
|
|
const pagina = validar.validarNumero(body.pagina, true);
|
|
|
|
return Multa.findAndCountAll({
|
|
include: [
|
|
{
|
|
model: Prestamo,
|
|
where: { idUsuario },
|
|
},
|
|
{ model: Infraccion },
|
|
],
|
|
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.idInfraccion;
|
|
delete res.rows[i].dataValues.idPrestamo;
|
|
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;
|
|
}
|
|
return { count: res.count, historialMultas: res.rows };
|
|
});
|
|
};
|
|
|
|
module.exports = historialMultas;
|