mandar correo
This commit is contained in:
@@ -1,25 +1,33 @@
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const dbHelper = '../../helper';
|
||||
const { validarId } = require(`../../helper/validar`);
|
||||
const correoAlumno = require(`../../helper/correoAlumno`);
|
||||
const gmail = require(`../../helper/gmail`);
|
||||
const dbPath = '../../db/tablas';
|
||||
const Alumno = require(`${dbPath}/Alumno`);
|
||||
const AlumnoHorario = require(`${dbPath}/AlumnoHorario`);
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Horario = require(`${dbPath}/Horario`);
|
||||
|
||||
const registrar = async (body) => {
|
||||
const idHorario = validarId(body.idHorario);
|
||||
const idAlumno = validarId(body.idAlumno);
|
||||
let turno = '';
|
||||
let alumno = {};
|
||||
let horario = {};
|
||||
let correo = {};
|
||||
|
||||
return Alumno.findOne({
|
||||
where: { idAlumno },
|
||||
include: [{ model: Carrera }],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este número de cuenta.');
|
||||
turno = res.turno;
|
||||
alumno = res;
|
||||
return Horario.findOne({ where: { idHorario } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este horario.');
|
||||
if (turno != res.turno)
|
||||
horario = res;
|
||||
if (alumno.turno != horario.turno)
|
||||
throw new Error('Este horario no corresponde con el turno del alumno.');
|
||||
return AlumnoHorario.findOne({ where: { idAlumno } });
|
||||
})
|
||||
@@ -30,8 +38,19 @@ const registrar = async (body) => {
|
||||
.then((res) => {
|
||||
if (res.length > 50)
|
||||
throw new Error('Ya no hay espacio en este horario.');
|
||||
return AlumnoHorario.create({ idAlumno, idHorario });
|
||||
correo = correoAlumno(
|
||||
alumno.numeroCuenta,
|
||||
alumno.Carrera.carrera,
|
||||
horario.horario
|
||||
);
|
||||
return gmail(
|
||||
correo.subject,
|
||||
'lemuelhelonmarquezrosas@gmail.com',
|
||||
// `${alumno.numeroCuenta@pcpuma.acatlan.unam.mx`
|
||||
correo.message
|
||||
);
|
||||
})
|
||||
.then((res) => AlumnoHorario.create({ idAlumno, idHorario }))
|
||||
.then((res) => ({ message: 'Se registro correctamente tu horario.' }));
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
const { validarTexto } = require('../../helper/validar');
|
||||
const AlumnoHorario = require(`../../db/tablas/AlumnoHorario`);
|
||||
const Horario = require(`../../db/tablas/Horario`);
|
||||
|
||||
const get = async (body) => {
|
||||
const turno = validarTexto(body.turno, 'El turno', 1);
|
||||
|
||||
return Horario.findAll({ where: { turno } });
|
||||
return Horario.findAll({ where: { turno } }).then(async (res) => {
|
||||
const data = [];
|
||||
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const registrados = await AlumnoHorario.findAll({
|
||||
where: { idHorario: res[i].idHorario },
|
||||
});
|
||||
|
||||
if (registrados.length <= 50) data.push(res[i]);
|
||||
}
|
||||
return data;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = get;
|
||||
|
||||
Reference in New Issue
Block a user