From 9dabe6f5022d5833da7c44e9591fdbd622240816 Mon Sep 17 00:00:00 2001 From: xXpuma99Xx <51341582+xXpuma99Xx@users.noreply.github.com> Date: Mon, 14 Feb 2022 01:35:22 -0600 Subject: [PATCH] mini errror --- .../Prestamo/prestamoNumeroInventario.js | 15 +++++++++++++-- .../Prestamo/regresoInmediatoNumeroInventario.js | 6 +++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/server/controller/Prestamo/prestamoNumeroInventario.js b/server/controller/Prestamo/prestamoNumeroInventario.js index 36f97b8..28fd861 100644 --- a/server/controller/Prestamo/prestamoNumeroInventario.js +++ b/server/controller/Prestamo/prestamoNumeroInventario.js @@ -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; }); }; diff --git a/server/controller/Prestamo/regresoInmediatoNumeroInventario.js b/server/controller/Prestamo/regresoInmediatoNumeroInventario.js index 4fe2c56..b721cc3 100644 --- a/server/controller/Prestamo/regresoInmediatoNumeroInventario.js +++ b/server/controller/Prestamo/regresoInmediatoNumeroInventario.js @@ -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,