correo corregido

This commit is contained in:
xXpuma99Xx
2021-10-28 10:43:35 -05:00
parent 72b8ec3a9c
commit 0ce86a74fd
2 changed files with 19 additions and 51 deletions
+6 -17
View File
@@ -1,7 +1,5 @@
const moment = require('moment');
const dbHelper = '../../helper';
const gmail = require(`${dbHelper}/gmail`);
const { correoAsistencia } = require(`${dbHelper}/correos`);
const { validarId } = require(`${dbHelper}/validar`);
const dbPath = '../../db/tablas';
const Alumno = require(`${dbPath}/Alumno`);
@@ -10,7 +8,6 @@ const ahora = moment();
const pasarLista = async (body) => {
const idAlumno = validarId(body.idAlumno);
let correo = {};
let horario = moment();
return Alumno.findOne({
@@ -19,25 +16,17 @@ const pasarLista = async (body) => {
})
.then((res) => {
if (!res) throw new Error('No existe este alumno.');
horario = moment(res.Horario.horario);
if (!res.idHorario)
throw new Error('Este alumno no tiene ningún horario asignado.');
if (res.asistio) throw new Error('Ya paso lista a este alumno.');
horario = moment(res.Horario.horario);
horario.add(-1, 'm');
if (ahora <= horario) throw new Error('Aun no es la hora del recorrido.');
horario.add(20, 'm');
horario.add(22, 'm');
if (ahora >= horario) throw new Error('Ya paso la hora del recorrido.');
return Alumno.update({ asistio: true }, { where: { idAlumno } });
})
.then((res) => {
correo = correoAsistencia();
return gmail(
correo.subject,
'lemuelhelonmarquezrosas@gmail.com',
correo.message
);
})
.then((res) => {
console.log(res);
return { message: 'Se paso lista correctamente.' };
});
.then((res) => ({ message: 'Se paso lista correctamente.' }));
};
module.exports = pasarLista;