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;
|
||||
Reference in New Issue
Block a user