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
@@ -32,8 +32,7 @@ const multarNumeroInventario = async (body) => {
500
);
let fechaFin = moment();
let prestamo = {};
let gravedad = '';
let idPrestamo = null;
return Operador.findOne({ where: { idOperador: idOperadorMulta } })
.then((res) => {
@@ -42,46 +41,29 @@ const multarNumeroInventario = 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: { activo: true },
include: [
{ model: Equipo, where: { numeroInventario } },
{ model: Usuario },
],
include: [{ model: Equipo, where: { numeroInventario } }],
});
})
.then((res) => {
if (!res)
throw new Error('No existe un prestamo activo con este equipo.');
prestamo = res;
return Multa.findOne({
where: {
idPrestamo: prestamo.idPrestamo,
idInfraccion: { [Op.ne]: 1 },
},
});
})
.then((res) => {
if (res)
throw new Error(
'Este préstamo ya ha sido usado para multar a un usuario.'
);
idPrestamo = res.idPrestamo;
return Usuario.update(
{ multa: true },
{ where: { idUsuario: prestamo.idUsuario } }
{ where: { idUsuario: res.idUsuario } }
);
})
.then(() =>
Multa.create({
descripcion,
fechaFin: fechaFin.format('YYYY-MM-DD'),
idPrestamo,
idOperadorMulta,
idInfraccion,
idPrestamo: prestamo.idPrestamo,
descripcion,
fechaFin: fechaFin.format('YYYY-MM-DD'),
})
)
.then(() => ({