registrar listo
This commit is contained in:
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user