73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
const validar = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const Carrera = require(`${dbPath}/Carrera`);
|
|
const CarreraHorario = require(`${dbPath}/CarreraHorario`);
|
|
const Horario = require(`${dbPath}/Horario`);
|
|
const Grupo = require(`${dbPath}/Grupo`);
|
|
const PrimerSemestre = require(`${dbPath}/PrimerSemestre`);
|
|
|
|
const get = async (body) => {
|
|
const idCarrera = validar.validarId(body.idCarrera);
|
|
const idGrupo = validar.validarId(body.idGrupo);
|
|
const idHorario = validar.validarId(body.idHorario);
|
|
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
|
const correo = validar.validarCorreo(body.correo);
|
|
|
|
/*
|
|
Falta
|
|
Enviar correo con qr de confirmación de su registro a su
|
|
email
|
|
*/
|
|
|
|
return Carrera.findOne({ where: { idCarrera } })
|
|
.then((res) => {
|
|
if (!res) throw new Error('No existe esta carrera.');
|
|
return Grupo.findOne({
|
|
where: { idGrupo },
|
|
});
|
|
})
|
|
.then((res) => {
|
|
if (!res) throw new Error('No existe este grupo.');
|
|
return Grupo.findOne({ where: { idGrupo, idCarrera } });
|
|
})
|
|
.then((res) => {
|
|
if (!res)
|
|
throw new Error('Este grupo no pertenece a la carrera indicada.');
|
|
if (res.grupo[0] === '2' && res.grupo[1] === '2')
|
|
throw new Error(
|
|
'Este grupo es de segundo semestre, no es valido para este registro.'
|
|
);
|
|
return Horario.findOne({ where: { idHorario } });
|
|
})
|
|
.then((res) => {
|
|
if (!res) throw new Error('No existe este horario.');
|
|
return CarreraHorario.findOne({ where: { idCarrera, idHorario } });
|
|
})
|
|
.then((res) => {
|
|
if (!res) throw new Error('Esta carrera no tiene asignado este horario.');
|
|
return PrimerSemestre.findOne({ where: { numeroCuenta } });
|
|
})
|
|
.then((res) => {
|
|
if (res) throw new Error('Ya se registro a este alumno al recorrido.');
|
|
return PrimerSemestre.findAll({
|
|
where: { idHorario },
|
|
});
|
|
})
|
|
.then((res) => {
|
|
if (res.length >= 50)
|
|
throw new Error('Este horario ya esta lleno, elige otro.');
|
|
return PrimerSemestre.create({
|
|
numeroCuenta,
|
|
correo,
|
|
idHorario,
|
|
idGrupo,
|
|
});
|
|
})
|
|
.then((res) => ({
|
|
message:
|
|
'Te haz registrado correctamente al recorrido. Te hemos mandado un mail a tu correo electrónico con tu comprobante de registro.',
|
|
}));
|
|
};
|
|
|
|
module.exports = get;
|