41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
const { Op } = require('sequelize');
|
|
const { validarNumeroEntero } = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const Carrera = require(`${dbPath}/Carrera`);
|
|
const Programa = require(`${dbPath}/Programa`);
|
|
const Servicio = require(`${dbPath}/Servicio`);
|
|
const Status = require(`${dbPath}/Status`);
|
|
const Usuario = require(`${dbPath}/Usuario`);
|
|
|
|
const alumno = async (body) => {
|
|
let idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario');
|
|
|
|
return Usuario.findOne({ where: { idUsuario } })
|
|
.then((res) => {
|
|
if (!res) throw new Error('No existe este usuario.');
|
|
if (res.idTipoUsuario !== 3)
|
|
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 }],
|
|
});
|
|
})
|
|
.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;
|
|
});
|
|
};
|
|
|
|
module.exports = alumno;
|