querries traen solo lo que necesitan

This commit is contained in:
xXpuma99Xx
2022-01-17 18:28:01 -06:00
parent 5623c90bda
commit bc146595a9
10 changed files with 180 additions and 145 deletions
@@ -36,7 +36,7 @@ const serviciosResponsable = async (body) => {
throw new Error('No es un usuario tipo responsable.');
return Servicio.findAndCountAll({
include: [
{ model: Programa, where: { idUsuario } },
{ model: Programa, where: { idUsuario }, attributes: [] },
{
model: Usuario,
where: {
@@ -45,36 +45,18 @@ const serviciosResponsable = async (body) => {
{ 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) => {
let data = [];
for (let i = 0; i < res.rows.length; i++) {
data.push({
idServicio: res.rows[i].idServicio,
fechaInicio: moment(res.rows[i].fechaInicio).format(),
fechaFin: moment(res.rows[i].fechaFin).format(),
cartaTermino: res.rows[i].cartaTermino,
idCuestionarioPrograma: res.rows[i].idCuestionarioPrograma,
Usuario: {
idUsuario: res.rows[i].Usuario.idUsuario,
usuario: res.rows[i].Usuario.usuario,
nombre: res.rows[i].Usuario.nombre,
},
Carrera: res.rows[i].Carrera,
Status: res.rows[i].Status,
});
}
return { count: res.count, serviciosResponsable: data };
});
.then((res) => ({ count: res.count, serviciosResponsable: res.rows }));
};
module.exports = serviciosResponsable;