listo equipos consecutivos
This commit is contained in:
@@ -53,7 +53,10 @@ const entregar = async (body) => {
|
||||
if (ahora > moment(`${ahora.format('YYYY-MM-DD')} 17:45`))
|
||||
update.horaFin = moment(`${ahora.format('YYYY-MM-DD')} 19:45`);
|
||||
else update.horaFin = ahora.add(2, 'h').format();
|
||||
return Equipo.update({ idStatus: 2 }, { where: { idEquipo } });
|
||||
return Equipo.update(
|
||||
{ idStatus: 2, prestado: true },
|
||||
{ where: { idEquipo } }
|
||||
);
|
||||
})
|
||||
.then(() => Prestamo.update(update, { where: { idPrestamo } }))
|
||||
.then(() =>
|
||||
|
||||
@@ -84,7 +84,7 @@ const pedir = async (body) => {
|
||||
'Tienes un préstamo activo. No puedes solicitar otro equipo de cómputo.'
|
||||
);
|
||||
}
|
||||
return Equipo.findOne({
|
||||
return Equipo.count({
|
||||
where: whereEquipo,
|
||||
include: [
|
||||
{
|
||||
@@ -92,7 +92,45 @@ const pedir = async (body) => {
|
||||
where: { idTipoCarrito, idModulo, activo: true },
|
||||
},
|
||||
],
|
||||
order: [['updatedAt']],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (res === 0)
|
||||
throw new Error(
|
||||
'No existe un equipo de cómputo con las características solicitadas. Intenta elegir otro tipo de equipo.'
|
||||
);
|
||||
return Equipo.count({
|
||||
where: { ...whereEquipo, prestado: false },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { idTipoCarrito, idModulo, activo: true },
|
||||
},
|
||||
],
|
||||
});
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res === 0)
|
||||
await Equipo.update(
|
||||
{ prestado: false },
|
||||
{
|
||||
where: { ...whereEquipo, prestado: true },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { idTipoCarrito, idModulo, activo: true },
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
return Equipo.findOne({
|
||||
where: { ...whereEquipo, prestado: false },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { idTipoCarrito, idModulo, activo: true },
|
||||
},
|
||||
],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
@@ -110,7 +148,7 @@ const pedir = async (body) => {
|
||||
idEquipo,
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
.then(() => {
|
||||
io.getIO().emit('actualizar', { idUsuario });
|
||||
return {
|
||||
message:
|
||||
|
||||
@@ -26,6 +26,11 @@ Equipo.init(
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: false,
|
||||
},
|
||||
prestado: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
|
||||
Reference in New Issue
Block a user