58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
const helperPath = '../../helper';
|
|
const gmail = require(`${helperPath}/gmail`);
|
|
const correos = require(`${helperPath}/correos`);
|
|
const { validarId } = require(`${helperPath}/validar`);
|
|
const dbPath = '../../db/tablas';
|
|
const Carrera = require(`${dbPath}/Carrera`);
|
|
const Grupo = require(`${dbPath}/Grupo`);
|
|
const GrupoHorario = require(`${dbPath}/GrupoHorario`);
|
|
const Horario = require(`${dbPath}/Horario`);
|
|
const TercerSemestre = require(`${dbPath}/TercerSemestre`);
|
|
|
|
const get = async (body) => {
|
|
const idTercerSemestre = validarId(body.idTercerSemestre);
|
|
let alumno = {};
|
|
let mail = {};
|
|
|
|
return TercerSemestre.findOne({
|
|
where: { idTercerSemestre },
|
|
include: [{ model: Grupo, include: [{ model: Carrera }] }],
|
|
})
|
|
.then((res) => {
|
|
if (!res) throw new Error('No existe esta alumno.');
|
|
if (res.deseaAsistir)
|
|
throw new Error('Ya se registro a este alumno al recorrido.');
|
|
alumno = res;
|
|
return GrupoHorario.findOne({
|
|
where: { idGrupo: alumno.idGrupo },
|
|
include: [{ model: Horario }],
|
|
});
|
|
})
|
|
.then((res) => {
|
|
mail = correos.correoTercerSemestre(
|
|
alumno.numeroCuenta,
|
|
alumno.nombre,
|
|
alumno.Grupo.Carrera.carrera,
|
|
res.Horario.horario
|
|
);
|
|
return gmail(
|
|
mail.subject,
|
|
'lemuelhelonmarquezrosas@gmail.com',
|
|
// `${res.numeroCuenta}@pcpuma.acatlan.unam.mx`
|
|
mail.message
|
|
);
|
|
})
|
|
.then((res) =>
|
|
TercerSemestre.update(
|
|
{ deseaAsistir: true },
|
|
{ where: { idTercerSemestre } }
|
|
)
|
|
)
|
|
.then((res) => ({
|
|
message:
|
|
'Te has registrado correctamente, hemos mandado tu comprobante a tu correo.',
|
|
}));
|
|
};
|
|
|
|
module.exports = get;
|