listo equipos consecutivos

This commit is contained in:
xXpuma99Xx
2022-02-22 15:16:46 -06:00
parent ee27a9db64
commit 48d882bbd2
3 changed files with 50 additions and 4 deletions
+41 -3
View File
@@ -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: