api completa
This commit is contained in:
@@ -1,26 +1,44 @@
|
||||
const Invitado = require('../../db/tablas/Invitado');
|
||||
const Profesor = require('../../db/tablas/Profesor');
|
||||
const Premiacion = require('../../db/tablas/Premiacion');
|
||||
const validar = require('../../helper/validar');
|
||||
const { correo } = require('../../helper/correos');
|
||||
const gmail = require('../../helper/gmail');
|
||||
const ProfesorPremiacion = require('../../db/tablas/ProfesorPremiacion');
|
||||
|
||||
const infoInvitados = async (body) => {
|
||||
const idProfesor = validar.validarNumeroEntero(body.idProfesor, 'idProfesor');
|
||||
const idPremiacion = validar.validarNumeroEntero(
|
||||
body.idPremiacion,
|
||||
'idPremiacion'
|
||||
);
|
||||
const invitados = body.invitados;
|
||||
const numeroInvitados = invitados.length;
|
||||
|
||||
const premiacion = await Premiacion.findOne({ where: idPremiacion });
|
||||
if (!premiacion)
|
||||
throw new Error('No existe ninguna premiación con este id con este id.');
|
||||
|
||||
invitados.forEach((invitado) => {
|
||||
if (invitado.edad < 18)
|
||||
throw new Error('Los invitados deben de ser mayores de edad.');
|
||||
if (invitado.edad < 12)
|
||||
throw new Error(
|
||||
'Alguno de sus invitados no cuenta con la edad suficiente.'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
if (numeroInvitados > 3)
|
||||
throw new Error('El número de invitados no puede ser mayor que 3.');
|
||||
|
||||
const prof = await Profesor.findOne({ where: idProfesor });
|
||||
if (prof.numeroInvitados)
|
||||
const profPrem = await ProfesorPremiacion.findOne({
|
||||
where: { idProfesor, idPremiacion },
|
||||
});
|
||||
if (!profPrem)
|
||||
throw new Error(
|
||||
'No existe ningún profesor con este id en esta premiación.'
|
||||
);
|
||||
if (profPrem.numeroInvitados)
|
||||
throw new Error('A este profesor ya se le han guardado sus invitados.');
|
||||
prof.update({ numeroInvitados: numeroInvitados });
|
||||
profPrem.update({ numeroInvitados: numeroInvitados });
|
||||
|
||||
const respuesta = [];
|
||||
for (let i = 0; i < numeroInvitados; i++) {
|
||||
@@ -40,23 +58,26 @@ const infoInvitados = async (body) => {
|
||||
nombreCompleto: nombre,
|
||||
edad: edad,
|
||||
idProfesor: idProfesor,
|
||||
idPremiacion: idPremiacion,
|
||||
});
|
||||
if (!res)
|
||||
throw new Error('No se ha podido ingresar los datos del invitado');
|
||||
respuesta.push(res);
|
||||
}
|
||||
|
||||
const dataProf = await Profesor.findOne({ where: idProfesor });
|
||||
const Mail = correo(
|
||||
dataProf.nombre,
|
||||
dataProf.numeroTrabajador,
|
||||
dataProf.numeroInvitados
|
||||
profPrem.idProfesor,
|
||||
profPrem.idPremiacion,
|
||||
premiacion.premiacion,
|
||||
premiacion.fecha,
|
||||
premiacion.hora
|
||||
);
|
||||
|
||||
const dataProf = await Profesor.findOne({ where: idProfesor });
|
||||
gmail(
|
||||
Mail.subject,
|
||||
`yosoymarco3@gmail.com`,
|
||||
// `${dataProf.numeroTrabajador}@pcpuma.acatlan.unam.mx`,
|
||||
// `jeremy@acatlan.unam.mx`,
|
||||
`${dataProf.numeroTrabajador}@pcpuma.acatlan.unam.mx`,
|
||||
Mail.message
|
||||
);
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
const Invitado = require('../../db/tablas/Invitado');
|
||||
const Profesor = require('../../db/tablas/Profesor')
|
||||
const Profesor = require('../../db/tablas/Profesor');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
|
||||
const get = () => Invitado.findAll({include: [{ model: Profesor }],});
|
||||
const get = async (query) => {
|
||||
const idPremiacion = validarNumeroEntero(
|
||||
query.idPremiacion,
|
||||
'idPremiacion',
|
||||
true
|
||||
);
|
||||
|
||||
module.exports = get;
|
||||
const invitados = await Invitado.findAll({
|
||||
where: { idPremiacion },
|
||||
include: [{ model: Profesor }],
|
||||
});
|
||||
if (!invitados) throw new Error('No se ha podido traer a los invitados');
|
||||
return invitados;
|
||||
};
|
||||
|
||||
module.exports = get;
|
||||
|
||||
Reference in New Issue
Block a user