listo equipos consecutivos
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user