Files
servicio_social_api/server/controller/Servicio/alumno.js
T

60 lines
1.7 KiB
JavaScript
Raw Normal View History

const { Op } = require('sequelize');
2022-01-02 15:07:49 -06:00
const { validarNumeroEntero } = require('../../helper/validar');
2021-05-05 18:49:23 -05:00
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`);
2020-11-19 11:47:23 -06:00
const alumno = async (body) => {
2022-01-02 15:07:49 -06:00
let idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario');
2020-11-19 11:47:23 -06:00
return Usuario.findOne({ where: { idUsuario } })
.then((res) => {
if (!res) throw new Error('No existe este usuario.');
if (res.idTipoUsuario !== 3)
2021-01-14 03:13:37 -06:00
throw new Error('No es un usuario de tipo alumno.');
2020-11-19 11:47:23 -06:00
return Servicio.findOne({
where: { idUsuario, idStatus: { [Op.not]: 10 } },
2022-01-17 18:28:01 -06:00
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'
2022-01-17 18:28:01 -06:00
],
2020-11-19 11:47:23 -06:00
});
})
.then((res) => {
if (!res) throw new Error('No existe este servicio social.');
2021-01-14 03:13:37 -06:00
return res;
2020-11-19 11:47:23 -06:00
});
};
module.exports = alumno;