From ac944e50703c2d39673376d016c2de0a5c6efd04 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Sun, 11 Jul 2021 23:58:16 -0500 Subject: [PATCH] listo --- server/controller/CarreraHorario/get.js | 3 +-- server/controller/PrimerSemestre/registrar.js | 25 +++++++++++++++---- server/controller/TercerSemestre/get.js | 1 - server/routes/PrimerSemestre.js | 18 +++++++++++++ server/routes/index.js | 1 + 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 server/routes/PrimerSemestre.js diff --git a/server/controller/CarreraHorario/get.js b/server/controller/CarreraHorario/get.js index 8e7ff91..0e5e47c 100644 --- a/server/controller/CarreraHorario/get.js +++ b/server/controller/CarreraHorario/get.js @@ -1,4 +1,3 @@ -const { Op, json } = require('sequelize'); const { validarId } = require('../../helper/validar'); const dbPath = '../../db/tablas'; const Carrera = require(`${dbPath}/Carrera`); @@ -25,7 +24,7 @@ const get = async (body) => { where: { idHorario: res[i].Horario.idHorario }, }).then((res) => res.length); - if (lugaresOcupados < 50) + if (lugaresOcupados <= 50) data.push({ Horario: res[i].Horario, lugares: 50 - lugaresOcupados }); } return data; diff --git a/server/controller/PrimerSemestre/registrar.js b/server/controller/PrimerSemestre/registrar.js index f46a017..c71025f 100644 --- a/server/controller/PrimerSemestre/registrar.js +++ b/server/controller/PrimerSemestre/registrar.js @@ -2,7 +2,7 @@ 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 Horario = require(`${dbPath}/Horario`); const Grupo = require(`${dbPath}/Grupo`); const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); @@ -18,7 +18,6 @@ const get = async (body) => { 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 } }) @@ -35,14 +34,29 @@ const get = async (body) => { .then((res) => { if (!res) throw new Error('Este grupo no pertenece a la carrera indicada.'); - return DiaHora.findOne({ where: { idHorario } }); + 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('Ese horario no existe.'); + 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, nombre, @@ -52,7 +66,8 @@ const get = async (body) => { }); }) .then((res) => ({ - message: 'Se ha registrado correctamente al alumno al recorrido.', + message: + 'Te haz registrado correctamente al recorrido. Te hemos mandado un mail a tu correo electrónico con tu comprobante de registro.', })); }; diff --git a/server/controller/TercerSemestre/get.js b/server/controller/TercerSemestre/get.js index f87f6c9..6e04333 100644 --- a/server/controller/TercerSemestre/get.js +++ b/server/controller/TercerSemestre/get.js @@ -1,4 +1,3 @@ -const moment = require('moment'); const { validarNumeroCuenta } = require('../../helper/validar'); const dbPath = '../../db/tablas'; const Carrera = require(`${dbPath}/Carrera`); diff --git a/server/routes/PrimerSemestre.js b/server/routes/PrimerSemestre.js new file mode 100644 index 0000000..5f647b0 --- /dev/null +++ b/server/routes/PrimerSemestre.js @@ -0,0 +1,18 @@ +const express = require('express'); +const app = express(); +const route = '/primer_semestre'; +const controllerPath = '../controller/PrimerSemestre'; +const registrar = require(`${controllerPath}/registrar`); + +// POST +app.post(`${route}/registrar`, (req, res) => { + return registrar(req.body) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + +module.exports = app; diff --git a/server/routes/index.js b/server/routes/index.js index 2b28725..59ec4b6 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -4,6 +4,7 @@ const app = express(); app.use(require('./Carrera')); app.use(require('./CarreraHorario')); app.use(require('./Grupo')); +app.use(require('./PrimerSemestre')); app.use(require('./TercerSemestre')); module.exports = app;