From a6520e89a5f1a9e0ccb7340c5ba02f2c1973dede Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Sun, 11 Jul 2021 18:32:38 -0500 Subject: [PATCH] registro primer grado a medias --- server/controller/PrimerSemestre/registrar.js | 59 +++++++++++++++++++ server/controller/TercerSemestre/get.js | 4 ++ server/controller/TercerSemestre/registrar.js | 5 ++ 3 files changed, 68 insertions(+) create mode 100644 server/controller/PrimerSemestre/registrar.js diff --git a/server/controller/PrimerSemestre/registrar.js b/server/controller/PrimerSemestre/registrar.js new file mode 100644 index 0000000..ed0397f --- /dev/null +++ b/server/controller/PrimerSemestre/registrar.js @@ -0,0 +1,59 @@ +const validar = require('../../helper/validar'); +const dbPath = '../../db/tablas'; +const Carrera = require(`${dbPath}/Carrera`); +const CarreraDiaHora = require(`${dbPath}/CarreraDiaHora`); +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 idDiaHora = validar.validarId(body.idDiaHora); + 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 CarreraDiaHora + */ + + 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: { idDiaHora } }); + }) + .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, + idDiaHora, + idGrupo, + }); + }) + .then((res) => ({ + message: 'Se ha registrado correctamente al alumno al recorrido.', + })); +}; + +module.exports = get; diff --git a/server/controller/TercerSemestre/get.js b/server/controller/TercerSemestre/get.js index 64ff6a6..cc914b5 100644 --- a/server/controller/TercerSemestre/get.js +++ b/server/controller/TercerSemestre/get.js @@ -7,6 +7,10 @@ const TercerSemestre = require(`${dbPath}/TercerSemestre`); const get = async (body) => { const numeroCuenta = validarNumeroCuenta(body.numeroCuenta); + /* + Falta + Buscar el horario que le toca + */ return TercerSemestre.findOne({ where: { numeroCuenta }, include: [{ model: Grupo, include: [{ model: Carrera }] }], diff --git a/server/controller/TercerSemestre/registrar.js b/server/controller/TercerSemestre/registrar.js index 897954d..a929fa5 100644 --- a/server/controller/TercerSemestre/registrar.js +++ b/server/controller/TercerSemestre/registrar.js @@ -5,6 +5,11 @@ const TercerSemestre = require(`${dbPath}/TercerSemestre`); const get = async (body) => { const idTercerSemestre = validarId(body.idTercerSemestre); + /* + Falta + Enviar correo con qr de confirmación de su registro a su + email pcpuma + */ return TercerSemestre.findOne({ where: { idTercerSemestre } }) .then((res) => { if (!res) throw new Error('No existe esta alumno.');