From bb160cdc82c6e0fdfb2b440b3feb316c7ecacc5f Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Thu, 29 Apr 2021 21:22:57 -0500 Subject: [PATCH] correcion logica regreso y recoger --- server/controller/Prestamo/recoger.js | 3 +++ server/controller/Prestamo/regresar.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/server/controller/Prestamo/recoger.js b/server/controller/Prestamo/recoger.js index 6610669..f7012bb 100644 --- a/server/controller/Prestamo/recoger.js +++ b/server/controller/Prestamo/recoger.js @@ -18,6 +18,9 @@ const recoger = async (body) => { }) .then((res) => { if (!res) throw new Error('No existe este prestamo.'); + if (!res.activo) throw new Error('Este prestamo ya no esta activo.'); + if (res.Equipo.enUso) + throw new Error('Ya se entrego el equipo al usuario.'); return Equipo.update( { enUso: true }, { where: { idEquipo: res.Equipo.idEquipo } } diff --git a/server/controller/Prestamo/regresar.js b/server/controller/Prestamo/regresar.js index a849097..cbdc208 100644 --- a/server/controller/Prestamo/regresar.js +++ b/server/controller/Prestamo/regresar.js @@ -20,6 +20,10 @@ const recoger = async (body) => { }) .then((res) => { if (!res) throw new Error('No existe este prestamo.'); + if (!res.activo) throw new Error('Este prestamo ya no esta activo.'); + if (!res.Equipo.enUso) + throw new Error('Aun no se ha entregado el equipo al usuario.'); + if (res) throw new Error('.'); return Equipo.update( { enUso: false, apartado: false }, { where: { idEquipo: res.Equipo.idEquipo } }