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