hisotrial reportes y mutlas

This commit is contained in:
2021-09-02 14:55:56 -05:00
parent b1f7a15b2a
commit 7f44e197e8
5 changed files with 98 additions and 1 deletions
@@ -0,0 +1,35 @@
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;
@@ -0,0 +1,29 @@
const validar = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Reporte = require(`${dbPath}/Reporte`);
const Prestamo = require(`${dbPath}/Prestamo`);
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 }],
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, historialReportes: res.rows };
});
};
module.exports = historialReportes;
+4 -1
View File
@@ -2,6 +2,7 @@ const { validarId, validarTexto } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Reporte = require(`${dbPath}/Reporte`);
const Prestamo = require(`${dbPath}/Prestamo`);
let idEquipo = null;
const reportar = async (body) => {
const idPrestamo = validarId(body.idPrestamo);
@@ -10,11 +11,13 @@ const reportar = async (body) => {
return Prestamo.findOne({ where: { idPrestamo } })
.then((res) => {
if (!res) throw new Error('No existe este prestamo.');
console.log(res.dataValues);
idEquipo = res.idEquipo;
return Reporte.findOne({ where: { idPrestamo } });
})
.then((res) => {
if (res) throw new Error('Ya existe un reporte con este prestamo.');
return Reporte.create({ descripcion, idPrestamo });
return Reporte.create({ descripcion, idPrestamo, idEquipo });
})
.then((res) => ({ message: 'Se levanto correctamente el reporte.' }));
};