32 lines
912 B
JavaScript
32 lines
912 B
JavaScript
const { validarNumeroEntero } = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const Multa = require(`${dbPath}/Multa`);
|
|
const Operador = require(`${dbPath}/Operador`);
|
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
|
|
|
const historialMultasEquipo = async (body) => {
|
|
const pagina = validarNumeroEntero(body.pagina, 'página', false);
|
|
const idEquipo = validarNumeroEntero(body.idEquipo, 'id equipo', true);
|
|
|
|
return Multa.findAndCountAll({
|
|
include: [
|
|
{
|
|
model: Prestamo,
|
|
where: { idEquipo },
|
|
attributes: ['idPrestamo'],
|
|
},
|
|
{
|
|
model: Operador,
|
|
as: 'OperadorMulta',
|
|
attributes: ['idOperador', 'operador'],
|
|
},
|
|
],
|
|
attributes: ['idMulta', 'descripcion', 'fechaFin', 'createdAt'],
|
|
limit: 25,
|
|
offset: 25 * (pagina - 1),
|
|
order: [['createdAt', 'DESC']],
|
|
});
|
|
};
|
|
|
|
module.exports = historialMultasEquipo;
|