60 lines
1.7 KiB
JavaScript
60 lines
1.7 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,
|
|
attributes: [
|
|
'idPrograma',
|
|
'institucion',
|
|
'dependencia',
|
|
'programa',
|
|
'clavePrograma',
|
|
],
|
|
},
|
|
],
|
|
attributes: [
|
|
'idServicio',
|
|
'creditos',
|
|
'correo',
|
|
'telefono',
|
|
'direccion',
|
|
'fechaInicio',
|
|
'fechaFin',
|
|
'fechaLiberacion',
|
|
'fechaNacimiento',
|
|
'informeGlobal',
|
|
'programaInterno',
|
|
'profesor',
|
|
'createdAt',
|
|
'idCuestionarioAlumno',
|
|
'idCuestionarioAlumno2'
|
|
],
|
|
});
|
|
})
|
|
.then((res) => {
|
|
if (!res) throw new Error('No existe este servicio social.');
|
|
return res;
|
|
});
|
|
};
|
|
|
|
module.exports = alumno;
|