cancelar
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
const Modulo = require('../../db/tablas/Modulo');
|
||||
|
||||
const get = async () => Modulo.findAll();
|
||||
|
||||
module.exports = get;
|
||||
@@ -0,0 +1,34 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
|
||||
const cancelar = async (body) => {
|
||||
const idPrestamo = validar.validarId(body.idPrestamo);
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { idPrestamo },
|
||||
include: [{ model: Equipo }],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Este prestamo no existe.');
|
||||
if (!res.activo)
|
||||
throw new Error(
|
||||
'Este prestamo ya no esta activo, ya no se puede cancelar.'
|
||||
);
|
||||
if (res.Equipo.enUso)
|
||||
throw new Error(
|
||||
'El equipo ya fue entregado al usuario, ya no se puede cancelar.'
|
||||
);
|
||||
return Equipo.update(
|
||||
{ apartado: false },
|
||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
||||
);
|
||||
})
|
||||
.then((res) =>
|
||||
Prestamo.update({ activo: false }, { where: { idPrestamo } })
|
||||
)
|
||||
.then((res) => ({ message: 'Se cancelo el prestamo correctamente.' }));
|
||||
};
|
||||
|
||||
module.exports = cancelar;
|
||||
@@ -57,7 +57,7 @@ const pedir = async (body) => {
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { idTipoCarrito, idModulo },
|
||||
where: { idTipoCarrito, idModulo, activo: true },
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
},
|
||||
{ model: Status },
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
const Status = require('../../db/tablas/Status');
|
||||
|
||||
const get = async () => Status.findAll();
|
||||
|
||||
module.exports = get;
|
||||
@@ -1,4 +1,3 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const TipoCarrito = require('../../db/tablas/TipoCarrito');
|
||||
|
||||
const get = async () => TipoCarrito.findAll();
|
||||
|
||||
Reference in New Issue
Block a user