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
+20 -5
View File
@@ -15,16 +15,31 @@ const admin = async (body) => {
return CasoEspecial.findOne({
where: { idCasoEspecial },
include: [
{ model: Usuario, include: [{ model: TipoUsuario }] },
{
model: Usuario,
include: [{ model: TipoUsuario }],
attributes: ['idUsuario', 'usuario', 'nombre'],
},
{ model: Carrera },
{ model: Status },
],
attributes: [
'idCasoEspecial',
'creditos',
'correo',
'telefono',
'institucion',
'dependencia',
'motivo',
'direccion',
'fechaInicio',
'fechaFin',
'fechaNacimiento',
'archivoZip',
'createdAt',
],
}).then((res) => {
if (!res) throw new Error('No existe este Caso Especial.');
delete res.dataValues.Usuario.dataValues.password;
delete res.dataValues.idUsuario;
delete res.dataValues.idCarrera;
delete res.dataValues.idStatus;
return res;
});
};
@@ -35,19 +35,16 @@ const serviciosEspeciales = async (body) => {
{ nombre: { [Op.like]: `%${nombre}%` } },
],
},
attributes: ['idUsuario', 'usuario', 'nombre'],
},
{ model: Carrera },
{ model: Status, where },
],
attributes: ['idCasoEspecial', 'fechaInicio', 'fechaFin', 'createdAt'],
order: [['updatedAt', 'DESC']],
limit: 25,
offset: 25 * (pagina - 1),
}).then((res) => {
for (let i = 0; i < res.rows.length; i++) {
// delete res.rows[i].dataValues.idUsuario
}
return { count: res.count, serviciosEspeciales: res.rows };
});
}).then((res) => ({ count: res.count, serviciosEspeciales: res.rows }));
};
module.exports = serviciosEspeciales;