registrar listo

This commit is contained in:
2021-10-23 06:42:04 -05:00
parent 2c14d4ee08
commit d61b71ff72
5 changed files with 57 additions and 20 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
const { validarNumeroCuenta } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Carrera = require(`${dbPath}/Carrera`);
const Alumno = require(`${dbPath}/Alumno`);
const Carrera = require(`${dbPath}/Carrera`);
const get = async (body) => {
const numeroCuenta = validarNumeroCuenta(body.numeroCuenta);
@@ -11,7 +11,7 @@ const get = async (body) => {
include: [{ model: Carrera }],
}).then((res) => {
if (!res) throw new Error('No existe este número de cuenta.');
delete res.idCarrera;
delete res.dataValues.idCarrera;
return res;
});
};
@@ -0,0 +1,38 @@
const { validarId } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Alumno = require(`${dbPath}/Alumno`);
const AlumnoHorario = require(`${dbPath}/AlumnoHorario`);
const Horario = require(`${dbPath}/Horario`);
const registrar = async (body) => {
const idHorario = validarId(body.idHorario);
const idAlumno = validarId(body.idAlumno);
let turno = '';
return Alumno.findOne({
where: { idAlumno },
})
.then((res) => {
if (!res) throw new Error('No existe este número de cuenta.');
turno = res.turno;
return Horario.findOne({ where: { idHorario } });
})
.then((res) => {
if (!res) throw new Error('No existe este horario.');
if (turno != res.turno)
throw new Error('Este horario no corresponde con el turno del alumno.');
return AlumnoHorario.findOne({ where: { idAlumno } });
})
.then((res) => {
if (res) throw new Error('Este alumno ya tiene un horario seleccionado.');
return AlumnoHorario.findAll({ where: { idHorario } });
})
.then((res) => {
if (res.length > 50)
throw new Error('Ya no hay espacio en este horario.');
return AlumnoHorario.create({ idAlumno, idHorario });
})
.then((res) => ({ message: 'Se registro correctamente tu horario.' }));
};
module.exports = registrar;
+2 -3
View File
@@ -1,6 +1,5 @@
const { validarTexto, validar } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Horario = require(`${dbPath}/Horario`);
const { validarTexto } = require('../../helper/validar');
const Horario = require(`../../db/tablas/Horario`);
const get = async (body) => {
const turno = validarTexto(body.turno, 'El turno', 1);