querries traen solo lo que necesitan
This commit is contained in:
@@ -13,20 +13,53 @@ const admin = async (body) => {
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
include: [
|
||||
{ model: Usuario, include: [{ model: TipoUsuario }] },
|
||||
{
|
||||
model: Usuario,
|
||||
include: [{ model: TipoUsuario }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
},
|
||||
{ model: Carrera },
|
||||
{ model: Status },
|
||||
{ model: Programa, include: [{ model: Usuario }] },
|
||||
{
|
||||
model: Programa,
|
||||
include: [
|
||||
{
|
||||
model: Usuario,
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idPrograma',
|
||||
'institucion',
|
||||
'dependencia',
|
||||
'programa',
|
||||
'clavePrograma',
|
||||
'acatlan',
|
||||
],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idServicio',
|
||||
'creditos',
|
||||
'correo',
|
||||
'telefono',
|
||||
'direccion',
|
||||
'fechaInicio',
|
||||
'fechaFin',
|
||||
'fechaLiberacion',
|
||||
'fechaNacimiento',
|
||||
'cartaAceptacion',
|
||||
'cartaTermino',
|
||||
'informeGlobal',
|
||||
'programaInterno',
|
||||
'profesor',
|
||||
'vistoBuenoAcatlan',
|
||||
'createdAt',
|
||||
'idCuestionarioAlumno',
|
||||
'idCuestionarioPrograma',
|
||||
],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este servicio social.');
|
||||
delete res.dataValues.Usuario.dataValues.password;
|
||||
delete res.dataValues.Programa.dataValues.idUsuario;
|
||||
delete res.dataValues.Programa.dataValues.Usuario.dataValues.password;
|
||||
delete res.dataValues.idUsuario;
|
||||
delete res.dataValues.idCarrera;
|
||||
delete res.dataValues.idStatus;
|
||||
delete res.dataValues.idPrograma;
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -17,22 +17,40 @@ const alumno = async (body) => {
|
||||
throw new Error('No es un usuario de tipo alumno.');
|
||||
return Servicio.findOne({
|
||||
where: { idUsuario, idStatus: { [Op.not]: 10 } },
|
||||
include: [{ model: Carrera }, { model: Status }, { model: Programa }],
|
||||
include: [
|
||||
{ model: Carrera },
|
||||
{ model: Status },
|
||||
{
|
||||
model: Programa,
|
||||
attributes: [
|
||||
'idPrograma',
|
||||
'institucion',
|
||||
'dependencia',
|
||||
'programa',
|
||||
'clavePrograma',
|
||||
],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idServicio',
|
||||
'creditos',
|
||||
'correo',
|
||||
'telefono',
|
||||
'direccion',
|
||||
'fechaInicio',
|
||||
'fechaFin',
|
||||
'fechaLiberacion',
|
||||
'fechaNacimiento',
|
||||
'informeGlobal',
|
||||
'programaInterno',
|
||||
'profesor',
|
||||
'createdAt',
|
||||
'idCuestionarioAlumno',
|
||||
],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este servicio social.');
|
||||
delete res.dataValues.idUsuario;
|
||||
delete res.dataValues.idCarrera;
|
||||
delete res.dataValues.idStatus;
|
||||
delete res.dataValues.idPrograma;
|
||||
delete res.dataValues.updatedAt;
|
||||
delete res.dataValues.carpeta;
|
||||
delete res.dataValues.cartaAceptacion;
|
||||
delete res.dataValues.cartaTermino;
|
||||
delete res.dataValues.vistoBuenoAcatlan;
|
||||
delete res.dataValues.idCuestionarioPrograma;
|
||||
delete res.dataValues.Programa.idUsuario;
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -36,33 +36,16 @@ const serviciosAdmin = 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(),
|
||||
createdAt: moment(res.rows[i].createdAt).format(),
|
||||
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, serviciosAdmin: data };
|
||||
});
|
||||
}).then((res) => ({ count: res.count, serviciosAdmin: res.rows }));
|
||||
};
|
||||
|
||||
module.exports = serviciosAdmin;
|
||||
|
||||
@@ -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