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