52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
const moment = require('moment');
|
|
const { Op } = require('sequelize');
|
|
const validar = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const Carrera = require(`${dbPath}/Carrera`);
|
|
const Servicio = require(`${dbPath}/Servicio`);
|
|
const Status = require(`${dbPath}/Status`);
|
|
const Usuario = require(`${dbPath}/Usuario`);
|
|
|
|
const serviciosAdmin = async (body) => {
|
|
const pagina = validar.validarNumero(
|
|
body.pagina,
|
|
'página',
|
|
false,
|
|
null,
|
|
true,
|
|
true
|
|
);
|
|
const where = body.idStatus
|
|
? { idStatus: validar.validarNumeroEntero(body.idStatus, 'id status') }
|
|
: {};
|
|
const nombre = body.nombre
|
|
? validar.validarTexto(body.nombre, 'nombre', true, 60)
|
|
: '';
|
|
const numeroCuenta = body.numeroCuenta
|
|
? validar.validarNumeroCuenta(body.numeroCuenta)
|
|
: '';
|
|
|
|
return Servicio.findAndCountAll({
|
|
include: [
|
|
{
|
|
model: Usuario,
|
|
where: {
|
|
[Op.and]: [
|
|
{ usuario: { [Op.like]: `%${numeroCuenta}%` } },
|
|
{ nombre: { [Op.like]: `%${nombre}%` } },
|
|
],
|
|
},
|
|
attributes: ['idUsuario', 'usuario', 'nombre'],
|
|
},
|
|
{ model: Carrera },
|
|
{ model: Status, where },
|
|
],
|
|
attributes: ['idServicio', 'fechaInicio', 'fechaFin', 'createdAt'],
|
|
order: [['updatedAt', 'DESC']],
|
|
limit: 25,
|
|
offset: 25 * (pagina - 1),
|
|
}).then((res) => ({ count: res.count, serviciosAdmin: res.rows }));
|
|
};
|
|
|
|
module.exports = serviciosAdmin;
|