already registred
This commit is contained in:
@@ -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;
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user