diff --git a/server/controller/Prestamo/cancelar.js b/server/controller/Prestamo/cancelar.js index 16aa136..06f2fb2 100644 --- a/server/controller/Prestamo/cancelar.js +++ b/server/controller/Prestamo/cancelar.js @@ -26,7 +26,10 @@ const cancelar = async (body) => { ); }) .then((res) => - Prestamo.update({ activo: false }, { where: { idPrestamo } }) + Prestamo.update( + { activo: false, cancelado: true }, + { where: { idPrestamo } } + ) ) .then((res) => ({ message: 'Se cancelo el prestamo correctamente.' })); }; diff --git a/server/controller/Prestamo/entregar.js b/server/controller/Prestamo/entregar.js index 02f8efc..f925f77 100644 --- a/server/controller/Prestamo/entregar.js +++ b/server/controller/Prestamo/entregar.js @@ -28,7 +28,7 @@ const entregar = async (body) => { if (!res.activo) throw new Error('Este prestamo ya no esta activo.'); else if (res.Equipo.enUso) throw new Error('Ya se entrego el equipo al usuario.'); - else if (moment(res.horaInicio) < ahora) { + else if (moment(res.horaMaxRecoger) < ahora) { await Equipo.update({ apartado: false }, { where: { idEquipo } }); await Prestamo.update({ activo: false }, { where: { idPrestamo } }); throw new Error( @@ -38,7 +38,14 @@ const entregar = async (body) => { return Equipo.update({ enUso: true }, { where: { idEquipo } }); }) .then((res) => { - Prestamo.update({ idOperadorEntrega }, { where: { idPrestamo } }); + Prestamo.update( + { + idOperadorEntrega, + horaInicio: ahora.format(), + horaFin: ahora.add(2, 'h').format(), + }, + { where: { idPrestamo } } + ); }) .then((res) => { return Equipo.findOne({ diff --git a/server/controller/Prestamo/pedir.js b/server/controller/Prestamo/pedir.js index 716ca27..4fd46f3 100644 --- a/server/controller/Prestamo/pedir.js +++ b/server/controller/Prestamo/pedir.js @@ -76,9 +76,7 @@ const pedir = async (body) => { }) .then((res) => Prestamo.create({ - horaInicio: ahora.add(10, 'm').format(), - // horaInicio: ahora.add(1, 'm').format(), - horaFin: ahora.add(120, 'm').format(), + horaMaxRecoger: ahora.add(10, 'm'), idUsuario, idEquipo, }) diff --git a/server/controller/Prestamo/status.js b/server/controller/Prestamo/status.js index b716e49..b14c0fd 100644 --- a/server/controller/Prestamo/status.js +++ b/server/controller/Prestamo/status.js @@ -62,7 +62,7 @@ const status = async (body) => { message: 'El equipo ya fue entregado al usuario.', prestamo: res, }; - } else if (moment(res.horaInicio) < ahora) { + } else if (moment(res.horaMaxRecoger) < ahora) { await Equipo.update( { apartado: false }, { where: { idEquipo: res.Equipo.idEquipo } } diff --git a/server/db/tablas/Prestamo.js b/server/db/tablas/Prestamo.js index 9683a3c..88ff448 100644 --- a/server/db/tablas/Prestamo.js +++ b/server/db/tablas/Prestamo.js @@ -16,22 +16,33 @@ Prestamo.init( }, horaInicio: { type: DataTypes.DATE, - allowNull: false, + allowNull: true, + defaultValue: null, }, horaFin: { type: DataTypes.DATE, - allowNull: false, + allowNull: true, + defaultValue: null, }, horaEntrega: { type: DataTypes.DATE, allowNull: true, defaultValue: null, }, + horaMaxRecoger: { + type: DataTypes.DATE, + allowNull: false, + }, activo: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: true, }, + cancelado: { + type: DataTypes.BOOLEAN, + allowNull: true, + defaultValue: null, + }, }, { sequelize,