109 lines
3.5 KiB
JavaScript
109 lines
3.5 KiB
JavaScript
const connection = require('../conf/connection.js');
|
|
const express = require('express');
|
|
var path = require('path');
|
|
const nodemailer = require("nodemailer");
|
|
const fs = require("fs");
|
|
|
|
|
|
var app = express()
|
|
|
|
function query(consulta) {
|
|
return new Promise(function(resolve, reject) {
|
|
connection.query(`${consulta}`, (error, results, files) => {
|
|
if (error) reject(error);
|
|
resolve(results);
|
|
});
|
|
})
|
|
}
|
|
|
|
|
|
|
|
async function sendEmail( destination ) {
|
|
|
|
// Generate test SMTP service account from ethereal.email
|
|
// Only needed if you don't have a real mail account for testing
|
|
let testAccount = await nodemailer.createTestAccount();
|
|
|
|
// create reusable transporter object using the default SMTP transport
|
|
let transporter = nodemailer.createTransport({
|
|
service: "Gmail",
|
|
port: 587,
|
|
secure: false, // true for 465, false for other ports
|
|
auth: {
|
|
user: 'asinea103@fa.unam.mx', // generated ethereal user
|
|
pass: 'As1n34103++'
|
|
},
|
|
});
|
|
|
|
// send mail with defined transport object
|
|
let info = await transporter.sendMail({
|
|
from: '"ASINEA 2020" <asinea103@fa.unam.mx>', // sender address
|
|
to: `"${destination}"`, // list of receivers
|
|
subject: "Problemas con tu comprobante de pago ASINEA 2020", // Subject line
|
|
text: `
|
|
Hola,
|
|
|
|
Hemos tenido problemas para visualizar el comprobante de pago que adjuntó en la plataforma de registro, por lo que su inscripción no ha podido ser validada.
|
|
|
|
Le pedimos, por favor, ingresar y hacer nuevamente el envío del mismo para poder continuar con el proceso de inscripción.
|
|
|
|
Cualquier duda puede ponerse en contacto con nosotros
|
|
`, // plain text body
|
|
|
|
|
|
});
|
|
|
|
console.log("Message sent: %s", info.messageId);
|
|
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
|
|
|
|
// Preview only available when sending through an Ethereal account
|
|
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
|
|
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
|
|
}
|
|
|
|
app.post('/rechazarPago', async(req, res) => {
|
|
try {
|
|
let data = req.body;
|
|
if( typeof( data.idPersona) === 'undefined' )
|
|
res.status(200).json({ error: true, msj: `No se encotro el ID de la persona en los datos: ${error}` });
|
|
|
|
let sqlQuery = `update persona persona set envioComprobante = false, requiereFactura = false where idPersona = ${data.idPersona};`;
|
|
await query(sqlQuery);
|
|
|
|
|
|
sqlQuery = `select * from persona where idPersona = ${data.idPersona};`;
|
|
let datos = await query(sqlQuery);
|
|
|
|
datos = datos[0];
|
|
|
|
sqlQuery = `delete from comprobante where idPersona = ${data.idPersona};`;
|
|
await query(sqlQuery);
|
|
|
|
if(datos.requiereFactura === true){
|
|
sqlQuery = `delete from factura where idPersona = ${data.idPersona};`;
|
|
await query(sqlQuery);
|
|
|
|
sqlQuery = `update persona set requiereFactura = false where idPersona = ${data.idPersona};`;
|
|
await query(sqlQuery);
|
|
}
|
|
|
|
|
|
await sendEmail( datos.correo );
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ error: false, msj: "exito"});
|
|
return;
|
|
}
|
|
catch(error){
|
|
console.log(error);
|
|
res.status(400).json({ error: true, msj: `Sucedio un error al actualizar el pago: ${error}` });
|
|
return;
|
|
}
|
|
});
|
|
|
|
|
|
|
|
module.exports = app;
|