From e015b1fe540c627edfc62cf1f6b58e7dd70d3aa0 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Wed, 14 Jul 2021 13:58:43 -0500 Subject: [PATCH] =?UTF-8?q?aparentemente=20versi=C3=B3n=20final?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +-- server/controller/PrimerSemestre/registrar.js | 11 ++++++- server/controller/TercerSemestre/registrar.js | 30 ++++++++++++++----- server/helper/correos.js | 14 ++++++--- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 0c9058f..954fc05 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "api", + "name": "citas_recorridos_api", "version": "1.0.0", - "description": "Esta es la plantilla para una api", + "description": "Esta es la api del sistema de recorridos de acatlan.", "main": "index.js", "scripts": { "test": "node ./server/config/test", diff --git a/server/controller/PrimerSemestre/registrar.js b/server/controller/PrimerSemestre/registrar.js index 87e81cd..641cf85 100644 --- a/server/controller/PrimerSemestre/registrar.js +++ b/server/controller/PrimerSemestre/registrar.js @@ -17,10 +17,13 @@ const get = async (body) => { const correo = validar.validarCorreo(body.correo); const nombre = validar.validarTexto(body.nombre, 'El nombre', 70); let mail = {}; + let horario = {}; + let carrera = {}; return Carrera.findOne({ where: { idCarrera } }) .then((res) => { if (!res) throw new Error('No existe esta carrera.'); + carrera = res; return Grupo.findOne({ where: { idGrupo }, }); @@ -40,6 +43,7 @@ const get = async (body) => { }) .then((res) => { if (!res) throw new Error('No existe este horario.'); + horario = res; return CarreraHorario.findOne({ where: { idCarrera, idHorario } }); }) .then((res) => { @@ -64,7 +68,12 @@ const get = async (body) => { }); }) .then((res) => { - mail = correos(res.nombre, res.numeroCuenta); + mail = correos.correoPrimerSemestre( + res.numeroCuenta, + res.nombre, + carrera.carrera, + horario.horario + ); return gmail(mail.subject, res.correo, mail.message); }) .then((res) => ({ diff --git a/server/controller/TercerSemestre/registrar.js b/server/controller/TercerSemestre/registrar.js index 9a3f143..1b651a2 100644 --- a/server/controller/TercerSemestre/registrar.js +++ b/server/controller/TercerSemestre/registrar.js @@ -3,22 +3,38 @@ 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 = {}; - /* - Falta - Enviar correo con qr de confirmación de su registro a su - email pcpuma - */ - return TercerSemestre.findOne({ where: { idTercerSemestre } }) + + 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.'); - mail = correos(res.nombre, res.numeroCuenta); + 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', diff --git a/server/helper/correos.js b/server/helper/correos.js index 739b321..637f88e 100644 --- a/server/helper/correos.js +++ b/server/helper/correos.js @@ -1,9 +1,11 @@ const moment = require('moment'); const correoPrimerSemestre = (numeroCuenta, nombre, lic, date) => { + const fecha = moment(date); + return { subject: `Comprobante de registro recorrido.`, - message: `

Estimada(o) nombre ${nombre}

+ message: `

Estimada(o) ${nombre}

Alumna(o) de la Generación 2022,
Licenciatura: ${lic}

@@ -13,7 +15,9 @@ const correoPrimerSemestre = (numeroCuenta, nombre, lic, date) => {

- Te esperamos en la entrada peatonal de la Facultad (sobre Av. San Juan Totoltepec), el próximo ${fecha.year()}/${fecha.month()}/${fecha.date()} a las ${fecha.hour()}:${ + Te esperamos en la entrada peatonal de la Facultad (sobre Av. San Juan Totoltepec), el próximo ${fecha.year()}/${ + fecha.month() + 1 + }/${fecha.date()} a las ${fecha.hour()}:${ fecha.minute() < 10 ? '0' + fecha.minute() : fecha.minute() }.

@@ -65,12 +69,14 @@ const correoTercerSemestre = (numeroCuenta, nombre, lic, date) => { return { subject: `Comprobante de registro recorrido.`, - message: `

Estimada(o) nombre ${nombre}

+ message: `

Estimada(o) ${nombre}

Alumna(o) de la Generación 2021,
Licenciatura: ${lic}

Gracias por registrarte para participar en este recorrido por la FES Acatlán, tu Facultad. La cita es en - la entrada peatonal (sobre Av. San Juan Totoltepec), el próximo ${fecha.year()}/${fecha.month()}/${fecha.date()} a las ${fecha.hour()}:${ + la entrada peatonal (sobre Av. San Juan Totoltepec), el próximo ${fecha.year()}/${ + fecha.month() + 1 + }/${fecha.date()} a las ${fecha.hour()}:${ fecha.minute() < 10 ? '0' + fecha.minute() : fecha.minute() }. Te pedimos asistir en la fecha y horarios asignados de acuerdo con tu licenciatura (no pueden ser modificados).