paginacion con find and caount all
2
This commit is contained in:
@@ -8,7 +8,7 @@ const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const serviciosEspeciales = async (body) => {
|
||||
const pagina = validar.validarId(body.pagina);
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
const where = body.idStatus
|
||||
? { idStatus: validar.validarId(body.idStatus) }
|
||||
: { idStatus: { [Op.gt]: 10 } };
|
||||
@@ -18,9 +18,8 @@ const serviciosEspeciales = async (body) => {
|
||||
const numeroCuenta = body.numeroCuenta
|
||||
? validar.validarNumeroCuenta(body.numeroCuenta)
|
||||
: '';
|
||||
const data = [];
|
||||
|
||||
return CasoEspecial.findAll({
|
||||
return CasoEspecial.findAndCountAll({
|
||||
include: [
|
||||
{
|
||||
model: Usuario,
|
||||
@@ -34,25 +33,13 @@ const serviciosEspeciales = async (body) => {
|
||||
{ model: Status, where },
|
||||
],
|
||||
order: [['updatedAt', 'DESC']],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
}).then((res) => {
|
||||
for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++)
|
||||
data.push({
|
||||
idCasoEspecial: res[i].idCasoEspecial,
|
||||
createdAt: res[i].createdAt,
|
||||
Usuario: {
|
||||
idUsuario: res[i].Usuario.idUsuario,
|
||||
usuario: res[i].Usuario.usuario,
|
||||
nombre: res[i].Usuario.nombre,
|
||||
TipoUsuario: res[i].Usuario.TipoUsuario,
|
||||
},
|
||||
Carrera: res[i].Carrera,
|
||||
Status: res[i].Status,
|
||||
});
|
||||
return {
|
||||
registros: res.length,
|
||||
faltantes: res.length - data.length - (pagina - 1) * 25,
|
||||
servicios: data,
|
||||
};
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
// delete res.rows[i].dataValues.idUsuario
|
||||
}
|
||||
return { count: res.count, serviciosEspeciales: res.rows };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const serviciosAdmin = async (body) => {
|
||||
const pagina = validar.validarId(body.pagina);
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
const where = body.idStatus
|
||||
? { idStatus: validar.validarId(body.idStatus) }
|
||||
: {};
|
||||
@@ -18,9 +18,8 @@ const serviciosAdmin = async (body) => {
|
||||
const numeroCuenta = body.numeroCuenta
|
||||
? validar.validarNumeroCuenta(body.numeroCuenta)
|
||||
: '';
|
||||
const data = [];
|
||||
|
||||
return Servicio.findAll({
|
||||
return Servicio.findAndCountAll({
|
||||
include: [
|
||||
{
|
||||
model: Usuario,
|
||||
@@ -34,27 +33,13 @@ const serviciosAdmin = async (body) => {
|
||||
{ model: Status, where },
|
||||
],
|
||||
order: [['updatedAt', 'DESC']],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
}).then((res) => {
|
||||
for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++)
|
||||
data.push({
|
||||
idServicio: res[i].idServicio,
|
||||
fechaInicio: res[i].fechaInicio,
|
||||
fechaFin: res[i].fechaFin,
|
||||
createdAt: res[i].createdAt,
|
||||
Usuario: {
|
||||
idUsuario: res[i].Usuario.idUsuario,
|
||||
usuario: res[i].Usuario.usuario,
|
||||
nombre: res[i].Usuario.nombre,
|
||||
TipoUsuario: res[i].Usuario.TipoUsuario,
|
||||
},
|
||||
Carrera: res[i].Carrera,
|
||||
Status: res[i].Status,
|
||||
});
|
||||
return {
|
||||
registros: res.length,
|
||||
faltantes: res.length - data.length - (pagina - 1) * 25,
|
||||
servicios: data,
|
||||
};
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
// delete res.rows[i].dataValues.idUsuario
|
||||
}
|
||||
return { count: res.count, serviciosAdmin: res.rows };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const serviciosResponsable = async (body) => {
|
||||
const pagina = validar.validarId(body.pagina);
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
const where = body.idStatus
|
||||
? { idStatus: validar.validarId(body.idStatus) }
|
||||
@@ -21,14 +21,13 @@ const serviciosResponsable = async (body) => {
|
||||
const numeroCuenta = body.numeroCuenta
|
||||
? validar.validarNumeroCuenta(body.numeroCuenta)
|
||||
: '';
|
||||
const data = [];
|
||||
|
||||
return Usuario.findOne({ where: { idUsuario } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
if (res.idTipoUsuario !== 2)
|
||||
throw new Error('No es un usuario tipo responsable.');
|
||||
return Servicio.findAll({
|
||||
return Servicio.findAndCountAll({
|
||||
include: [
|
||||
{ model: Programa, where: { idUsuario } },
|
||||
{
|
||||
@@ -43,30 +42,15 @@ const serviciosResponsable = async (body) => {
|
||||
{ model: Status, where },
|
||||
],
|
||||
order: [['updatedAt', 'DESC']],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++)
|
||||
data.push({
|
||||
idServicio: res[i].idServicio,
|
||||
fechaInicio: res[i].fechaInicio,
|
||||
fechaFin: res[i].fechaFin,
|
||||
cartaTermino: res[i].cartaTermino,
|
||||
idCuestionarioPrograma: res[i].idCuestionarioPrograma,
|
||||
Usuario: {
|
||||
idUsuario: res[i].Usuario.idUsuario,
|
||||
usuario: res[i].Usuario.usuario,
|
||||
nombre: res[i].Usuario.nombre,
|
||||
TipoUsuario: res[i].Usuario.TipoUsuario,
|
||||
},
|
||||
Carrera: res[i].Carrera,
|
||||
Status: res[i].Status,
|
||||
});
|
||||
return {
|
||||
registros: res.length,
|
||||
faltantes: res.length - data.length - (pagina - 1) * 25,
|
||||
servicios: data,
|
||||
};
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
// delete res.rows[i].dataValues.idUsuario
|
||||
}
|
||||
return { count: res.count, serviciosResponsable: res.rows };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -4,35 +4,31 @@ const dbPath = '../../db/tablas';
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
|
||||
const responsable = async (body) => {
|
||||
const pagina = validar.validarId(body.pagina);
|
||||
const responsables = async (body) => {
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
const nombre = body.nombre
|
||||
? validar.validarTexto(body.nombre, 'El nombre', 60)
|
||||
: '';
|
||||
const correo = body.correo
|
||||
? validar.validar(body.correo, 'El correo', 1000)
|
||||
: '';
|
||||
const data = [];
|
||||
|
||||
return Usuario.findAll({
|
||||
return Usuario.findAndCountAll({
|
||||
where: {
|
||||
usuario: { [Op.like]: `%${correo}%` },
|
||||
nombre: { [Op.like]: `%${nombre}%` },
|
||||
idTipoUsuario: 2,
|
||||
},
|
||||
include: [{ model: TipoUsuario }],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
}).then((res) => {
|
||||
for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++) {
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
delete res[i].dataValues.password;
|
||||
delete res[i].dataValues.idTipoUsuario;
|
||||
data.push(res[i]);
|
||||
}
|
||||
return {
|
||||
registros: res.length,
|
||||
faltantes: res.length - data.length - (pagina - 1) * 25,
|
||||
servicios: data,
|
||||
};
|
||||
return { count: res.count, responsables: res.rows };
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = responsable;
|
||||
module.exports = responsables;
|
||||
|
||||
Reference in New Issue
Block a user