This commit is contained in:
Lemuel Marquez
2021-06-29 09:55:18 -05:00
parent 1d071bbe31
commit b84c1312fc
5 changed files with 28 additions and 9 deletions
+4 -1
View File
@@ -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.' }));
};
+9 -2
View File
@@ -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({
+1 -3
View File
@@ -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,
})
+1 -1
View File
@@ -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 } }
+13 -2
View File
@@ -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,