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 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 };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user