60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
const validar = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const Carrera = require(`${dbPath}/Carrera`);
|
|
const CarreraHorario = require(`${dbPath}/CarreraHorario`);
|
|
const DiaHora = require(`${dbPath}/DiaHora`);
|
|
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 nombre = validar.validarTexto(body.nombre, 'El Nombre', 70);
|
|
const correo = validar.validarCorreo(body.correo);
|
|
|
|
/*
|
|
Falta
|
|
Enviar correo con qr de confirmación de su registro a su
|
|
email
|
|
Verificar que Dia Hora pertenezca a CarreraHorario
|
|
*/
|
|
|
|
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.');
|
|
return DiaHora.findOne({ where: { idHorario } });
|
|
})
|
|
.then((res) => {
|
|
if (!res) throw new Error('Ese horario no existe.');
|
|
return PrimerSemestre.findOne({ where: { numeroCuenta } });
|
|
})
|
|
.then((res) => {
|
|
if (res) throw new Error('Ya se registro a este alumno al recorrido.');
|
|
return PrimerSemestre.create({
|
|
numeroCuenta,
|
|
nombre,
|
|
correo,
|
|
idHorario,
|
|
idGrupo,
|
|
});
|
|
})
|
|
.then((res) => ({
|
|
message: 'Se ha registrado correctamente al alumno al recorrido.',
|
|
}));
|
|
};
|
|
|
|
module.exports = get;
|