already registred

This commit is contained in:
2022-05-25 21:21:40 -05:00
parent 79f82db59e
commit fc7ec840a4
2 changed files with 46 additions and 0 deletions
+35
View File
@@ -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;