listo
This commit is contained in:
@@ -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.' }));
|
||||
};
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
@@ -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 } }
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user