querries traen solo lo que necesitan
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user