diff --git a/server/controller/Profesor/yaRegistro.js b/server/controller/Profesor/yaRegistro.js new file mode 100644 index 0000000..76f32c7 --- /dev/null +++ b/server/controller/Profesor/yaRegistro.js @@ -0,0 +1,35 @@ +const Profesor = require('../../db/tablas/Profesor'); +const Premiacion = require('../../db/tablas/Premiacion'); +const ProfesorPremiacion = require('../../db/tablas/ProfesorPremiacion'); +const validar = require('../../helper/validar'); + +const yaRegistro = async (query) => { + console.log(query) + const idProfesor = validar.validarNumeroEntero( + query.idProfesor, + 'idProfesor' + ); + const idPremiacion = validar.validarNumeroEntero( + query.idPremiacion, + 'idPremiacion' + ); + + return Profesor.findOne({ where: { idProfesor } }).then((res) => { + if (!res) throw new Error('Este profesor no existe.'); + + return Premiacion.findOne({ where: { idPremiacion } }).then((res) => { + if (!res) throw new Error('Esta premiacion no existe.'); + + return ProfesorPremiacion.findOne({ + where: { idPremiacion, idProfesor }, + }).then((res) => { + if (!res) throw new Error('Este profesor no tiene premiaciones.'); + + if (res.numeroInvitados) return true; + return false; + }); + }); + }); +}; + +module.exports = yaRegistro; diff --git a/server/routes/Profesor.js b/server/routes/Profesor.js index 23b0ef3..e320073 100644 --- a/server/routes/Profesor.js +++ b/server/routes/Profesor.js @@ -10,6 +10,7 @@ const entradaInvitado = require(`${controllerPath}/entradaInvitado`); const cargarDatos = require(`${controllerPath}/cargarDatos`); const adscripciones = require(`${controllerPath}/adscripciones`); const premiaciones = require(`${controllerPath}/premiaciones`); +const yaRegistro = require(`${controllerPath}/yaRegistro`); app.post(`${route}/login`, (req, res) => { return login(req.body) @@ -51,6 +52,16 @@ app.get(`${route}/premiaciones`, (req, res) => { }); }); +app.get(`${route}/yaRegistro`, (req, res) => { + return yaRegistro(req.query) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + app.post( `${route}/cargarDatos`, // verificaToken,