opeardor multa y operador cancelacion

This commit is contained in:
2021-09-17 15:14:30 -05:00
parent f6efe944c7
commit 0dcd899b50
15 changed files with 93 additions and 36 deletions
@@ -8,6 +8,7 @@ const Prestamo = require(`${dbPath}/Prestamo`);
const Usuario = require(`${dbPath}/Usuario`);
const multar = async (body) => {
const idOperadorMulta = validar.validarId(body.idOperadorMulta);
const idInfraccion = validar.validarId(body.idInfraccion);
const numeroInventario = validar.validarAlfanumerico(
body.numeroInventario,
@@ -22,7 +23,11 @@ const multar = async (body) => {
let prestamo = {};
let fechaFin = moment();
return Infraccion.findOne({ where: { idInfraccion } })
return Operador.findOne({ where: { idOperador: idOperadorMulta } })
.then((res) => {
if (!res) throw new Error('No existe esta este operador.');
return Infraccion.findOne({ where: { idInfraccion } });
})
.then((res) => {
if (!res) throw new Error('No existe esta infracción.');
if (res.gravedad == '1') fechaFin.add(7, 'd');
@@ -52,6 +57,7 @@ const multar = async (body) => {
.then((res) =>
Multa.create({
descripcion,
idOperadorMulta,
idInfraccion,
idPrestamo: prestamo.idPrestamo,
fechaFin: fechaFin.format(),