40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
const { Op } = require('sequelize');
|
|
const validar = require('../../helper/validar');
|
|
const Servicio = require('../../db/tablas/Servicio');
|
|
const Usuario = require('../../db/tablas/Usuario');
|
|
const Carrera = require('../../db/tablas/Carrera');
|
|
const Status = require('../../db/tablas/Status');
|
|
const Programa = require('../../db/tablas/Programa');
|
|
|
|
const alumno = async (body) => {
|
|
let idUsuario = validar.validarId(body.idUsuario);
|
|
|
|
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;
|