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
+53 -45
View File
@@ -90,9 +90,9 @@
"integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA=="
},
"node_modules/@types/node": {
"version": "14.18.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.4.tgz",
"integrity": "sha512-swe3lD4izOJWHuxvsZdDFRq6S9i6koJsXOnQKYekhSO5JTizMVirUFgY/bUsaOJQj8oSD4oxmRYPBM/0b6jpdw=="
"version": "14.18.7",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.7.tgz",
"integrity": "sha512-UpLEO1iBG7esNPusSAjoZhWFK5Mfd8QfwWhHRrg5io13POn/stsBgTCba9suQaFflNA4tc0+6AFM3R6BZNng6A=="
},
"node_modules/abbrev": {
"version": "1.1.1",
@@ -1008,9 +1008,9 @@
}
},
"node_modules/follow-redirects": {
"version": "1.14.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.6.tgz",
"integrity": "sha512-fhUl5EwSJbbl8AR+uYL2KQDxLkdSjZGR36xy46AO7cOMTrCMON6Sa28FmAnC2tRTDbd/Uuzz3aJBv7EBN7JH8A==",
"version": "1.14.7",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",
"integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==",
"funding": [
{
"type": "individual",
@@ -1205,11 +1205,11 @@
}
},
"node_modules/google-p12-pem": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/google-p12-pem/-/google-p12-pem-3.1.2.tgz",
"integrity": "sha512-tjf3IQIt7tWCDsa0ofDQ1qqSCNzahXDxdAGJDbruWqu3eCg5CKLYKN+hi0s6lfvzYZ1GDVr+oDF9OOWlDSdf0A==",
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/google-p12-pem/-/google-p12-pem-3.1.3.tgz",
"integrity": "sha512-MC0jISvzymxePDVembypNefkAQp+DRP7dBE+zNUPaIjEspIlYg0++OrsNr248V9tPbz6iqtZ7rX1hxWA5B8qBQ==",
"dependencies": {
"node-forge": "^0.10.0"
"node-forge": "^1.0.0"
},
"bin": {
"gp12-pem": "build/src/bin/gp12-pem.js"
@@ -1269,9 +1269,9 @@
}
},
"node_modules/graceful-fs": {
"version": "4.2.8",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==",
"version": "4.2.9",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz",
"integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==",
"dev": true
},
"node_modules/gtoken": {
@@ -1967,22 +1967,30 @@
"integrity": "sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A=="
},
"node_modules/node-fetch": {
"version": "2.6.6",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz",
"integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==",
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/node-forge": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz",
"integrity": "sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA==",
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.2.1.tgz",
"integrity": "sha512-Fcvtbb+zBcZXbTTVwqGA5W+MKBj56UjVRevvchv5XrcyXbmNdesfZL37nlcWOfpgHhgmxApw3tQbTr4CqNmX4w==",
"engines": {
"node": ">= 6.0.0"
"node": ">= 6.13.0"
}
},
"node_modules/nodemailer": {
@@ -2471,9 +2479,9 @@
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
},
"node_modules/sequelize": {
"version": "6.12.4",
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.12.4.tgz",
"integrity": "sha512-P2E8TzlV3VwdvPqTS58ctIpcAOytXdaylUUfxxnALjtMmF6I+kfNtrqTP7WQFaenOboAtXPCJReZ9MPy+Zy/Ig==",
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.13.0.tgz",
"integrity": "sha512-p0dXXGZSc0Ng7CdGwlKN4P6DTRD/w9Ar2CnmHamNVDnqEWh6pMVOp3xrlG5+IWhbwrqL3SjIYEYt3Xog1vXRDw==",
"funding": [
{
"type": "opencollective",
@@ -3051,9 +3059,9 @@
"integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA=="
},
"@types/node": {
"version": "14.18.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.4.tgz",
"integrity": "sha512-swe3lD4izOJWHuxvsZdDFRq6S9i6koJsXOnQKYekhSO5JTizMVirUFgY/bUsaOJQj8oSD4oxmRYPBM/0b6jpdw=="
"version": "14.18.7",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.7.tgz",
"integrity": "sha512-UpLEO1iBG7esNPusSAjoZhWFK5Mfd8QfwWhHRrg5io13POn/stsBgTCba9suQaFflNA4tc0+6AFM3R6BZNng6A=="
},
"abbrev": {
"version": "1.1.1",
@@ -3771,9 +3779,9 @@
}
},
"follow-redirects": {
"version": "1.14.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.6.tgz",
"integrity": "sha512-fhUl5EwSJbbl8AR+uYL2KQDxLkdSjZGR36xy46AO7cOMTrCMON6Sa28FmAnC2tRTDbd/Uuzz3aJBv7EBN7JH8A=="
"version": "1.14.7",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",
"integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ=="
},
"forwarded": {
"version": "0.2.0",
@@ -3908,11 +3916,11 @@
}
},
"google-p12-pem": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/google-p12-pem/-/google-p12-pem-3.1.2.tgz",
"integrity": "sha512-tjf3IQIt7tWCDsa0ofDQ1qqSCNzahXDxdAGJDbruWqu3eCg5CKLYKN+hi0s6lfvzYZ1GDVr+oDF9OOWlDSdf0A==",
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/google-p12-pem/-/google-p12-pem-3.1.3.tgz",
"integrity": "sha512-MC0jISvzymxePDVembypNefkAQp+DRP7dBE+zNUPaIjEspIlYg0++OrsNr248V9tPbz6iqtZ7rX1hxWA5B8qBQ==",
"requires": {
"node-forge": "^0.10.0"
"node-forge": "^1.0.0"
}
},
"googleapis": {
@@ -3957,9 +3965,9 @@
}
},
"graceful-fs": {
"version": "4.2.8",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==",
"version": "4.2.9",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz",
"integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==",
"dev": true
},
"gtoken": {
@@ -4504,17 +4512,17 @@
"integrity": "sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A=="
},
"node-fetch": {
"version": "2.6.6",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz",
"integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==",
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
"requires": {
"whatwg-url": "^5.0.0"
}
},
"node-forge": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz",
"integrity": "sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA=="
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.2.1.tgz",
"integrity": "sha512-Fcvtbb+zBcZXbTTVwqGA5W+MKBj56UjVRevvchv5XrcyXbmNdesfZL37nlcWOfpgHhgmxApw3tQbTr4CqNmX4w=="
},
"nodemailer": {
"version": "6.7.2",
@@ -4888,9 +4896,9 @@
}
},
"sequelize": {
"version": "6.12.4",
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.12.4.tgz",
"integrity": "sha512-P2E8TzlV3VwdvPqTS58ctIpcAOytXdaylUUfxxnALjtMmF6I+kfNtrqTP7WQFaenOboAtXPCJReZ9MPy+Zy/Ig==",
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.13.0.tgz",
"integrity": "sha512-p0dXXGZSc0Ng7CdGwlKN4P6DTRD/w9Ar2CnmHamNVDnqEWh6pMVOp3xrlG5+IWhbwrqL3SjIYEYt3Xog1vXRDw==",
"requires": {
"@types/debug": "^4.1.7",
"debug": "^4.3.3",
+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;
+42 -9
View File
@@ -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;
});
};
+30 -12
View File
@@ -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;
});
};
+3 -20
View File
@@ -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;
+22 -15
View File
@@ -1,5 +1,6 @@
const validar = require('../../helper/validar');
const { crearToken } = require('../../middleware/autentificacion');
// const validarPath = '../../db/tablas';
const validar = require('../../helper/validar');
const { comparar } = require('../../helper/encriptar');
const dbPath = '../../db/tablas';
const Usuario = require(`${dbPath}/Usuario`);
@@ -21,20 +22,26 @@ const login = async (body) => {
return Usuario.findOne({
where: { usuario },
include: [{ model: TipoUsuario }],
}).then((res) => {
if (!res) throw new Error('No existe este usuario.');
if (!res.activo) throw new Error('Este usuario no esta activo.');
if (comparar(password, res.password)) {
delete res.dataValues.password;
delete res.dataValues.activo;
return {
Usuario: res,
token: crearToken(res.idUsuario),
};
}
throw new Error('La contraseña es incorrecta');
});
attributes: ['idUsuario', 'activo', 'password'],
})
.then((res) => {
if (!res) throw new Error('No existe este usuario.');
if (!res.activo) throw new Error('Este usuario no esta activo.');
if (!comparar(password, res.password))
throw new Error('La contraseña es incorrecta');
return Usuario.findOne({
where: { idUsuario: res.idUsuario },
include: [{ model: TipoUsuario }],
attributes: ['idUsuario', 'usuario', 'nombre'],
});
})
.then((res) => ({
Usuario: res,
token: crearToken({
idUsuario: res.idUsuario,
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
}),
}));
};
module.exports = login;
+1 -4
View File
@@ -6,10 +6,7 @@ const responsable = async (body) => {
return Usuario.findOne({
where: { idUsuario },
}).then((res) => {
delete res.dataValues.password;
delete res.dataValues.idTipoUsuario;
return res;
attributes: ['idUsuario', 'usuario', 'nombre', 'activo'],
});
};
+2 -7
View File
@@ -26,15 +26,10 @@ const responsables = async (body) => {
{ idTipoUsuario: 2 },
],
},
attributes: ['idUsuario', 'usuario', 'nombre', 'activo'],
limit: 25,
offset: 25 * (pagina - 1),
}).then((res) => {
for (let i = 0; i < res.rows.length; i++) {
delete res.rows[i].dataValues.password;
delete res.rows[i].dataValues.idTipoUsuario;
}
return { count: res.count, responsables: res.rows };
});
}).then((res) => ({ count: res.count, responsables: res.rows }));
};
module.exports = responsables;