multas aparentemente listas

This commit is contained in:
xXpuma99Xx
2022-02-13 20:38:54 -06:00
parent e285fe893d
commit cd90641c07
3 changed files with 50 additions and 68 deletions
+8 -35
View File
@@ -1,5 +1,4 @@
const moment = require('moment');
const { Op } = require('sequelize');
const validar = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Infraccion = require(`${dbPath}/Infraccion`);
@@ -31,8 +30,6 @@ const multar = async (body) => {
500
);
let fechaFin = moment();
let prestamo = {};
let gravedad = '';
return Operador.findOne({ where: { idOperador: idOperadorMulta } })
.then((res) => {
@@ -41,51 +38,27 @@ const multar = async (body) => {
})
.then((res) => {
if (!res) throw new Error('No existe esta infracción.');
// Checar si tiene una multa activa, agragar días a multa
gravedad = res.gravedad;
if (gravedad === '1') fechaFin.add(7, 'd');
if (res.gravedad === '1') fechaFin.add(7, 'd');
else fechaFin.add(100, 'y');
return Prestamo.findOne({
where: { idPrestamo },
include: [{ model: Usuario }],
});
return Prestamo.findOne({ where: { idPrestamo } });
})
.then((res) => {
if (!res) throw new Error('No existe este préstamo.');
prestamo = res;
return Prestamo.findOne({
where: { idUsuario: prestamo.idUsuario, activo: true },
});
})
.then((res) => {
if (res)
throw new Error(
'No se puede multar a este usuario ya que tiene un préstamo activo.'
);
return Multa.findOne({
where: { idPrestamo, idInfraccion: { [Op.ne]: 1 } },
});
})
.then((res) => {
if (res)
throw new Error(
'Este préstamo ya ha sido usado para multar a un usuario.'
);
return Usuario.update(
{ multa: true },
{ where: { idUsuario: prestamo.idUsuario } }
{ where: { idUsuario: res.idUsuario } }
);
})
.then((res) =>
.then(() =>
Multa.create({
descripcion,
fechaFin: fechaFin.format('YYYY-MM-DD'),
idPrestamo,
idOperadorMulta,
idInfraccion,
idPrestamo,
descripcion,
fechaFin: fechaFin.format('YYYY-MM-DD'),
})
)
.then((res) => ({
.then(() => ({
message: `Se levantó correctamente el reporte de multa.`,
}));
};