Files

38 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2022-02-01 06:44:34 -06:00
const { validarNumeroEntero } = require('../../helper/validar');
2021-09-02 14:55:56 -05:00
const dbPath = '../../db/tablas';
2021-09-17 14:28:13 -05:00
const Carrito = require(`${dbPath}/Carrito`);
2021-09-14 18:17:17 -05:00
const Equipo = require(`${dbPath}/Equipo`);
2021-09-17 14:28:13 -05:00
const Infraccion = require(`${dbPath}/Infraccion`);
const Modulo = require(`${dbPath}/Modulo`);
2021-09-14 18:17:17 -05:00
const Multa = require(`${dbPath}/Multa`);
const Operador = require(`${dbPath}/Operador`);
2021-09-02 14:55:56 -05:00
const Prestamo = require(`${dbPath}/Prestamo`);
2021-09-17 14:28:13 -05:00
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
2021-09-02 14:55:56 -05:00
2021-09-14 18:17:17 -05:00
const historialMultasUsuario = async (body) => {
2022-02-01 06:44:34 -06:00
const pagina = validarNumeroEntero(body.pagina, 'página', false);
const idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario', true);
2021-09-02 14:55:56 -05:00
return Multa.findAndCountAll({
include: [
{
model: Prestamo,
where: { idUsuario },
2022-02-13 13:34:54 -06:00
attributes: ['idPrestamo'],
2021-09-02 14:55:56 -05:00
},
2022-01-20 22:01:14 -06:00
{
model: Operador,
as: 'OperadorMulta',
attributes: ['idOperador', 'operador'],
},
2022-01-24 15:58:34 -06:00
{ model: Infraccion },
2021-09-02 14:55:56 -05:00
],
2022-01-20 22:01:14 -06:00
attributes: ['idMulta', 'descripcion', 'fechaFin', 'createdAt'],
2021-09-02 14:55:56 -05:00
limit: 25,
offset: 25 * (pagina - 1),
order: [['createdAt', 'DESC']],
2022-01-24 15:58:34 -06:00
});
2021-09-02 14:55:56 -05:00
};
2021-09-14 18:17:17 -05:00
module.exports = historialMultasUsuario;