60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
|
|
const connection = require('../conf/connection.js');
|
|
const express = require('express')
|
|
var app = express();
|
|
|
|
|
|
function query(consulta) {
|
|
return new Promise(function(resolve, reject) {
|
|
connection.query(`${consulta}`, (error, results, files) => {
|
|
if (error) reject(error);
|
|
resolve(results);
|
|
});
|
|
})
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/descargar_pdf', async (req, res) => {
|
|
|
|
let cad=`select * from persona where id_persona=${req.query.id_persona};`;
|
|
let ans=await query(cad);
|
|
let correo=ans[0].correo_electronico;
|
|
|
|
const send = require('gmail-send')({
|
|
user: 'daniel.adrian.ramirez.george@gmail.com',
|
|
pass: '753951852_dan',
|
|
to: `${correo}`,
|
|
subject: 'Comprobante de inscripción CIIE FES Acatlan',
|
|
text: 'Se adjunta el comprobante de inscripcion al Coloquio Internacional de Educacion.', // Plain text
|
|
|
|
});
|
|
|
|
|
|
const filepath = __dirname + `/../files/lista-${req.query.id_persona}.pdf`; // File to attach
|
|
|
|
|
|
await send({ // Overriding default parameters
|
|
//subject: 'attached '+filepath, // Override value set as default
|
|
files: [ filepath ],
|
|
}, function (err, res, full) {
|
|
if (err)
|
|
console.log('* [example 1.1] send() callback returned: res:', res);
|
|
// uncomment to see full response from Nodemailer:
|
|
// console.log('* [example 1.2] send() callback returned: full:', full);
|
|
});
|
|
|
|
|
|
console.log(correo);
|
|
|
|
return res.download(__dirname + `/../files/lista-${req.query.id_persona}.pdf`);
|
|
//return res.status(200).json({msj: "exito"});
|
|
})
|
|
|
|
module.exports = app; |