53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
const { validarNumeroEntero } = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const Carrito = require(`${dbPath}/Carrito`);
|
|
const Equipo = require(`${dbPath}/Equipo`);
|
|
const Modulo = require(`${dbPath}/Modulo`);
|
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
|
const Programa = require(`${dbPath}/Programa`);
|
|
const Status = require(`${dbPath}/Status`);
|
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
|
const Usuario = require(`${dbPath}/Usuario`);
|
|
|
|
const prestamo = async (body) => {
|
|
const idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario', true);
|
|
|
|
return Usuario.findOne({ where: { idUsuario } }).then((res) => {
|
|
if (!res) throw new Error('No existe este usuario.');
|
|
return Prestamo.findOne({
|
|
where: { idUsuario, activo: true },
|
|
include: [
|
|
{
|
|
model: Equipo,
|
|
include: [
|
|
{
|
|
model: Carrito,
|
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
|
attributes: ['idCarrito', 'sobrenombre'],
|
|
},
|
|
{ model: Status },
|
|
{ model: Programa },
|
|
],
|
|
attributes: [
|
|
'idEquipo',
|
|
'numeroSerie',
|
|
'numeroInventario',
|
|
'sobrenombre',
|
|
],
|
|
},
|
|
],
|
|
attributes: [
|
|
'idPrestamo',
|
|
'activo',
|
|
'horaMaxRecoger',
|
|
'horaInicio',
|
|
'horaFin',
|
|
'horaEntrega',
|
|
'createdAt',
|
|
],
|
|
});
|
|
});
|
|
};
|
|
|
|
module.exports = prestamo;
|