2021-04-28 23:58:55 -05:00
|
|
|
const validar = require('../../helper/validar');
|
|
|
|
|
const dbPath = '../../db/tablas';
|
2021-04-29 19:18:38 -05:00
|
|
|
const Carrera = require(`${dbPath}/Carrera`);
|
2021-04-28 23:58:55 -05:00
|
|
|
const Equipo = require(`${dbPath}/Equipo`);
|
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-28 23:58:55 -05:00
|
|
|
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
2021-04-29 19:18:38 -05:00
|
|
|
const Usuario = require(`${dbPath}/Usuario`);
|
2021-04-28 23:58:55 -05:00
|
|
|
|
|
|
|
|
const historialEquipo = 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 idEquipo = validar.validarNumeroEntero(
|
|
|
|
|
body.idEquipo,
|
|
|
|
|
'id equipo',
|
|
|
|
|
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: [
|
2022-01-20 22:01:14 -06:00
|
|
|
{
|
|
|
|
|
model: Equipo,
|
|
|
|
|
where: { idEquipo },
|
2022-02-13 12:33:38 -06:00
|
|
|
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
2022-01-20 22:01:14 -06:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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',
|
|
|
|
|
'canceladoUsuario',
|
2022-02-05 21:40:39 -06:00
|
|
|
'canceladoOperador',
|
2022-01-28 16:41:46 -06:00
|
|
|
'regresoInmediato',
|
2022-01-20 22:01:14 -06:00
|
|
|
'createdAt',
|
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-24 15:58:34 -06:00
|
|
|
});
|
2021-04-28 23:58:55 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = historialEquipo;
|