api completa
This commit is contained in:
@@ -1,21 +1,37 @@
|
||||
const Profesor = require('../../db/tablas/Profesor');
|
||||
const ProfesorPremiacion = require('../../db/tablas/ProfesorPremiacion');
|
||||
const validar = require('../../helper/validar');
|
||||
|
||||
const entradaInvitado = async (body) => {
|
||||
const idProfesor = validar.validarNumeroEntero(body.idProfesor, 'idProfesor');
|
||||
const idPremiacion = validar.validarNumeroEntero(
|
||||
body.idPremiacion,
|
||||
'idPremiacion'
|
||||
);
|
||||
|
||||
const profesor = await Profesor.findOne({ where: idProfesor });
|
||||
if (!profesor) throw new Error('Este profesor no existe');
|
||||
if (!profesor.noInvitados) throw new Error('Este profesor no registró a ninún invitado.')
|
||||
let noInvDentro = profesor.dataValues.numeroInvitadosDentro;
|
||||
let noInv = profesor.dataValues.numeroInvitados;
|
||||
if (!profesor) throw new Error('Este profesor no existe.');
|
||||
|
||||
const profPrem = await ProfesorPremiacion.findOne({
|
||||
where: { idPremiacion, idProfesor },
|
||||
});
|
||||
|
||||
if (!profPrem)
|
||||
throw new Error(
|
||||
'Este profesor no está registrado en esta entrega de medallas.'
|
||||
);
|
||||
if (!profPrem.numeroInvitados)
|
||||
throw new Error('Este profesor no registró a ninún invitado.');
|
||||
|
||||
let noInvDentro = profPrem.dataValues.numeroInvitadosDentro;
|
||||
let noInv = profPrem.dataValues.numeroInvitados;
|
||||
if (noInvDentro && noInvDentro >= noInv)
|
||||
throw new Error('Este profesor ya ingreso a todos sus invitados.');
|
||||
|
||||
const res = await profesor.update({ numeroInvitadosDentro: noInvDentro + 1 });
|
||||
const res = await profPrem.update({ numeroInvitadosDentro: noInvDentro + 1 });
|
||||
if (!res)
|
||||
throw new Error(
|
||||
'Ha ocurrido un error al actualizar los datos del profesor.'
|
||||
'Ha ocurrido un error al registrar los invitados del profesor.'
|
||||
);
|
||||
return res;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user