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
+9 -2
View File
@@ -2,11 +2,13 @@ const moment = require('moment');
const validar = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Infraccion = require(`${dbPath}/Infraccion`);
const Multa = require(`${dbPath}/Multa`);
const Operador = require(`${dbPath}/Operador`);
const Prestamo = require(`${dbPath}/Prestamo`);
const Usuario = require(`${dbPath}/Usuario`);
const Multa = require(`${dbPath}/Multa`);
const multar = async (body) => {
const idOperadorMulta = validar.validarId(body.idOperadorMulta);
const idInfraccion = validar.validarId(body.idInfraccion);
const idPrestamo = validar.validarId(body.idPrestamo);
const descripcion = validar.validarAlfanumerico(
@@ -17,7 +19,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');
@@ -44,6 +50,7 @@ const multar = async (body) => {
Multa.create({
descripcion,
fechaFin: fechaFin.format(),
idOperadorMulta,
idInfraccion,
idPrestamo,
})