mini errror

This commit is contained in:
xXpuma99Xx
2022-02-14 01:35:22 -06:00
parent 8e1592f769
commit 9dabe6f502
2 changed files with 18 additions and 3 deletions
@@ -1,3 +1,4 @@
const { Op } = require('sequelize');
const { validarAlfanumerico } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Carrera = require(`${dbPath}/Carrera`);
@@ -21,7 +22,14 @@ const prestamoNumeroInventario = async (body) => {
);
return Prestamo.findOne({
where: { activo: true },
where: {
[Op.or]: [
{ activo: true },
{
[Op.and]: [{ regresoInmediato: true }, { idOperadorRegreso: null }],
},
],
},
include: [
{
model: Equipo,
@@ -66,7 +74,10 @@ const prestamoNumeroInventario = async (body) => {
'createdAt',
],
}).then((res) => {
if (!res) throw new Error('No existe este préstamo.');
if (!res)
throw new Error(
'No existe un préstamo activo con este número de inventario.'
);
return res;
});
};
@@ -24,11 +24,15 @@ const regresoInmediatoNumeroInventario = async (body) => {
include: [{ model: Equipo, where: { numeroInventario } }],
})
.then(async (res) => {
if (!res) throw new Error('No existe este préstamo.');
if (!res)
throw new Error(
'No existe un préstamo activo con este número de inventario.'
);
if (!res.activo) throw new Error('Este préstamo ya no esta activo.');
if (res.Equipo.idStatus === 1)
throw new Error('Aún no se ha entregado el equipo al usuario.');
diferencia = parseInt((ahora - moment(res.horaFin)) / 60000);
idPrestamo = res.idPrestamo;
if (diferencia >= 15)
await Multa.create({
idPrestamo,