2021-04-28 23:58:55 -05:00
|
|
|
const validar = require('../../helper/validar');
|
|
|
|
|
const dbPath = '../../db/tablas';
|
|
|
|
|
const Carrito = require(`${dbPath}/Carrito`);
|
2021-04-29 19:18:38 -05:00
|
|
|
const Equipo = require(`${dbPath}/Equipo`);
|
2021-04-28 23:58:55 -05:00
|
|
|
const Modulo = require(`${dbPath}/Modulo`);
|
2021-04-29 21:11:32 -05:00
|
|
|
const Operador = require(`${dbPath}/Operador`);
|
2021-04-29 19:18:38 -05:00
|
|
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
2021-04-29 20:00:08 -05:00
|
|
|
const Programa = require(`${dbPath}/Programa`);
|
2021-04-28 23:58:55 -05:00
|
|
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
2021-04-29 19:18:38 -05:00
|
|
|
const Usuario = require(`${dbPath}/Usuario`);
|
2021-04-28 23:58:55 -05:00
|
|
|
|
|
|
|
|
const historialUsuario = async (body) => {
|
2022-02-01 09:48:07 -06:00
|
|
|
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
|
2022-01-03 16:47:25 -06:00
|
|
|
const idUsuario = validar.validarNumeroEntero(
|
|
|
|
|
body.idUsuario,
|
|
|
|
|
'id usuario',
|
|
|
|
|
true
|
|
|
|
|
);
|
2021-04-28 23:58:55 -05:00
|
|
|
|
2021-04-29 21:11:32 -05:00
|
|
|
return Prestamo.findAndCountAll({
|
2021-04-28 23:58:55 -05:00
|
|
|
include: [
|
|
|
|
|
{
|
|
|
|
|
model: Equipo,
|
|
|
|
|
include: [
|
|
|
|
|
{
|
|
|
|
|
model: Carrito,
|
|
|
|
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
2022-01-20 22:01:14 -06:00
|
|
|
attributes: ['idCarrito', 'sobrenombre'],
|
2021-04-28 23:58:55 -05:00
|
|
|
},
|
2021-04-29 20:00:08 -05:00
|
|
|
{ model: Programa },
|
2021-04-28 23:58:55 -05:00
|
|
|
],
|
2022-01-20 22:01:14 -06:00
|
|
|
attributes: [
|
|
|
|
|
'idEquipo',
|
|
|
|
|
'numeroSerie',
|
|
|
|
|
'numeroInventario',
|
|
|
|
|
'sobrenombre',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
model: Usuario,
|
|
|
|
|
where: { idUsuario },
|
|
|
|
|
attributes: ['idUsuario', 'usuario', 'nombre'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
model: Operador,
|
|
|
|
|
as: 'OperadorEntrega',
|
|
|
|
|
attributes: ['idOperador', 'operador'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
model: Operador,
|
|
|
|
|
as: 'OperadorRegreso',
|
|
|
|
|
attributes: ['idOperador', 'operador'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
model: Operador,
|
|
|
|
|
as: 'OperadorCancelacion',
|
|
|
|
|
attributes: ['idOperador', 'operador'],
|
2021-04-28 23:58:55 -05:00
|
|
|
},
|
|
|
|
|
],
|
2021-04-29 21:11:32 -05:00
|
|
|
limit: 25,
|
|
|
|
|
offset: 25 * (pagina - 1),
|
2021-06-23 14:20:29 -05:00
|
|
|
order: [['createdAt', 'DESC']],
|
2022-01-20 22:01:14 -06:00
|
|
|
attributes: [
|
|
|
|
|
'idPrestamo',
|
|
|
|
|
'activo',
|
|
|
|
|
'horaMaxRecoger',
|
|
|
|
|
'horaInicio',
|
|
|
|
|
'horaFin',
|
|
|
|
|
'horaEntrega',
|
|
|
|
|
'canceladoUsuario',
|
2022-01-28 16:41:46 -06:00
|
|
|
'regresoInmediato',
|
2022-01-20 22:01:14 -06:00
|
|
|
'createdAt',
|
|
|
|
|
],
|
2022-01-24 15:58:34 -06:00
|
|
|
});
|
2021-04-28 23:58:55 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = historialUsuario;
|