actualizacoion proyecto final
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
const connection = require('../conf/connection.js');
|
||||
const express = require('express')
|
||||
var app = express();
|
||||
var qr = require('./qr.js');
|
||||
|
||||
|
||||
app.get('/crear_pdf', async(req, res) => {
|
||||
await qr(req.query.id_persona).then((p) => {
|
||||
// console.log(req.query);
|
||||
// console.log(p);
|
||||
//res.download(__dirname + `/../files/lista-${req.query.id_persona}.pdf`);
|
||||
res.status(200).json({ error: false, msj: "exito" });
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
res.status(400).json({ error: true, msj: "Error al crear el comprobante", type: err });
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,255 @@
|
||||
const connection = require('../conf/connection.js');
|
||||
const express = require('express');
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
|
||||
var app = express()
|
||||
|
||||
|
||||
function query(consulta) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
connection.query(`${consulta}`, (error, results, files) => {
|
||||
if (error) reject(error);
|
||||
resolve(results);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function depurado(cadena) {
|
||||
if (cadena != null)
|
||||
return cadena.replace(/'/g, "''");
|
||||
else
|
||||
return null;
|
||||
}
|
||||
app.post('/datos_personales', async(req, res) => {
|
||||
let body = req.body;
|
||||
console.log(body);
|
||||
|
||||
try {
|
||||
let n_correo = depurado(body.correo);
|
||||
let cad = `select * from persona where correo='${n_correo}';`;
|
||||
let respuesta = await query(cad);
|
||||
if (respuesta.length != 0) {
|
||||
|
||||
res.status(400).json({ error: false, msj: "El correo ya se encuentra registrado" });
|
||||
return;
|
||||
}
|
||||
|
||||
let curp = body.curp;
|
||||
curp = depurado(curp);
|
||||
cad = `select * from persona where curp='${curp}';`;
|
||||
respuesta = await query(cad);
|
||||
if (respuesta.length != 0) {
|
||||
res.status(400).json({ error: false, msj: "El CURP ya esta registrado" });
|
||||
return;
|
||||
}
|
||||
|
||||
let n_nombre = depurado(body.nombre);
|
||||
let n_apellido_p = depurado(body.apellido_p);
|
||||
let n_apellido_m = depurado(body.apellido_m);
|
||||
let n_curp = curp;
|
||||
let n_genero = depurado(body.genero);
|
||||
let n_edad = body.edad;
|
||||
let n_telefono = depurado(body.telefono);
|
||||
let n_password = await bcrypt.hash(body.password, 10);
|
||||
let n_comunidad = depurado(body.comunidad);
|
||||
let n_situacion = depurado(body.situacion);
|
||||
let n_universidad = depurado(body.univrsidad);
|
||||
// console.log(n_pasword);
|
||||
|
||||
|
||||
// CREATE TABLE `persona` (
|
||||
// `id_persona` integer PRIMARY KEY NOT NULL AUTO_INCREMENT,
|
||||
// `nombre` varchar(100),
|
||||
// `apellidp_p` varchar(100),
|
||||
// `apellidp_m` varchar(100),
|
||||
// `curp` varchar(200),
|
||||
// `edad` integer,
|
||||
// `genero` varchar(10),
|
||||
// `telefono` varchar(50),
|
||||
// `correo` varchar(100),
|
||||
// `pasword` varchar(300),
|
||||
// `comunidad` varchar(50),
|
||||
// `situacion_academica` varchar(50)
|
||||
// );
|
||||
|
||||
cad = `insert into persona values (null,'${n_nombre}', '${n_apellido_p}', '${n_apellido_m}', '${n_curp}', ${n_edad}, '${n_genero}',
|
||||
'${n_telefono}','${n_correo}', '${n_password}', '${n_comunidad}', '${n_situacion}' ,'${ n_universidad}' );`;
|
||||
respuesta = query(cad);
|
||||
respuesta.then(async() => {
|
||||
|
||||
cad = `select id_persona from persona where correo='${n_correo}'`;
|
||||
let n_res = await query(cad);
|
||||
console.log(n_res);
|
||||
|
||||
|
||||
let id_persona = n_res[0].id_persona;
|
||||
|
||||
if (n_situacion == 'Alumno') {
|
||||
try {
|
||||
let n_cuenta = null;
|
||||
if (body.cuenta != undefined)
|
||||
n_cuenta = depurado(body.cuenta.toString());
|
||||
|
||||
let n_year = depurado(body.año.toString());
|
||||
let n_participacion = depurado(body.participacion);
|
||||
if (n_cuenta != null)
|
||||
cad = `insert into alumno values( ${id_persona}, '${n_cuenta}', '${n_year}' ) ;`;
|
||||
else
|
||||
cad = `insert into alumno values( ${id_persona}, null, '${n_year}' ) ;`;
|
||||
|
||||
|
||||
let n_ans = query(cad);
|
||||
n_ans.then(async() => {
|
||||
|
||||
if (body.conversatorio != undefined) {
|
||||
let con = body.conversatorio;
|
||||
cad = `insert into asistencia values(null, ${id_persona}, ${con.id_evento}, false, false , false , false, false, '${con.participacion}' );`;
|
||||
let n_q = await query(cad);
|
||||
cad = `update evento set cupo= cupo-1 where id_evento=${con.id_evento};`;
|
||||
n_q = await query(cad);
|
||||
}
|
||||
if (body.taller_a != undefined) {
|
||||
let ta = body.taller_a;
|
||||
cad = `insert into asistencia values(null, ${id_persona}, ${ta.id_evento}, false, false , false , false, false, '${ta.participacion}' );`;
|
||||
let n_q = await query(cad);
|
||||
cad = `update evento set cupo= cupo-1 where id_evento=${ta.id_evento};`;
|
||||
n_q = await query(cad);
|
||||
|
||||
}
|
||||
if (body.taller_p != undefined) {
|
||||
let ta = body.taller_p;
|
||||
cad = `insert into asistencia values(null, ${id_persona}, ${ta.id_evento}, false, false , false , false, false, '${ta.participacion}');`;
|
||||
let n_q = await query(cad);
|
||||
cad = `update evento set cupo= cupo-1 where id_evento=${ta.id_evento};`;
|
||||
n_q = await query(cad);
|
||||
|
||||
|
||||
}
|
||||
if (body.visitas != undefined) {
|
||||
let ta = body.visitas;
|
||||
cad = `insert into asistencia values(null, ${id_persona}, ${ta.id_evento}, false, false , false , false, false, '${ta.participacion}');`;
|
||||
let n_q = await query(cad);
|
||||
cad = `update evento set cupo= cupo-1 where id_evento=${ta.id_evento};`;
|
||||
n_q = await query(cad);
|
||||
|
||||
}
|
||||
if (body.magistral != undefined) {
|
||||
let ta = body.magistral;
|
||||
cad = `insert into asistencia values(null, ${id_persona}, ${ta.id_evento}, false, false , false , false, false, '${ta.participacion}' );`;
|
||||
let n_q = await query(cad);
|
||||
cad = `update evento set cupo= cupo-1 where id_evento=${ta.id_evento};`;
|
||||
n_q = await query(cad);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return res.status(200).json({ err: false, msj: "Exito", id_persona: id_persona });
|
||||
|
||||
|
||||
}).catch(async(err) => {
|
||||
console.log(err);
|
||||
|
||||
//se deberia borrar el registro anterio de persona;
|
||||
|
||||
return res.status(400).json({ err: true, msj: "Error al insirtar en la base en alumno", type: err });
|
||||
})
|
||||
} catch (err) {
|
||||
|
||||
//se deberia borrar el registro anterio de persona;
|
||||
console.log(err);
|
||||
return res.status(400).json({ err: true, msj: "Error al insirtar en la base en alumno", type: err });
|
||||
|
||||
}
|
||||
} else if (n_situacion == 'Académico') {
|
||||
try {
|
||||
let n_grado = depurado(body.grado);
|
||||
let n_asignatura = depurado(body.asignatura);
|
||||
let n_participacion = depurado(body.participacion);
|
||||
cad = `insert into academico values(${id_persona}, '${n_grado}', '${n_asignatura}' );`;
|
||||
let n_ans = query(cad);
|
||||
n_ans.then(async() => {
|
||||
|
||||
if (body.conversatorio != undefined) {
|
||||
let con = body.conversatorio;
|
||||
cad = `insert into asistencia values(null, ${id_persona}, ${con.id_evento}, false, false , false , false, false, '${con.participacion}');`;
|
||||
let n_q = await query(cad);
|
||||
cad = `update evento set cupo= cupo-1 where id_evento=${con.id_evento};`;
|
||||
n_q = await query(cad);
|
||||
}
|
||||
if (body.taller_a != undefined) {
|
||||
let ta = body.taller_a;
|
||||
cad = `insert into asistencia values(null, ${id_persona}, ${ta.id_evento}, false, false , false , false, false, '${ta.participacion}' );`;
|
||||
let n_q = await query(cad);
|
||||
cad = `update evento set cupo= cupo-1 where id_evento=${ta.id_evento};`;
|
||||
n_q = await query(cad);
|
||||
|
||||
}
|
||||
if (body.taller_p != undefined) {
|
||||
let ta = body.taller_p;
|
||||
cad = `insert into asistencia values(null, ${id_persona}, ${ta.id_evento}, false, false , false , false, false, '${ta.participacion}' );`;
|
||||
let n_q = await query(cad);
|
||||
cad = `update evento set cupo= cupo-1 where id_evento=${ta.id_evento};`;
|
||||
n_q = await query(cad);
|
||||
|
||||
|
||||
}
|
||||
if (body.visitas != undefined) {
|
||||
let ta = body.visitas;
|
||||
cad = `insert into asistencia values(null, ${id_persona}, ${ta.id_evento}, false, false , false , false, false, '${ta.participacion}' );`;
|
||||
let n_q = await query(cad);
|
||||
cad = `update evento set cupo= cupo-1 where id_evento=${ta.id_evento};`;
|
||||
n_q = await query(cad);
|
||||
|
||||
}
|
||||
if (body.magistral != undefined) {
|
||||
let ta = body.magistral;
|
||||
cad = `insert into asistencia values(null, ${id_persona}, ${ta.id_evento}, false, false , false , false, false, '${ta.participacion}' );`;
|
||||
let n_q = await query(cad);
|
||||
cad = `update evento set cupo= cupo-1 where id_evento=${ta.id_evento};`;
|
||||
n_q = await query(cad);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return res.status(200).json({ err: false, msj: "Exito", id_persona: id_persona });
|
||||
}).catch(async err => {
|
||||
//se deberia borrar el registro anterio de persona;
|
||||
//se deberia borrar el registro anterio de persona;
|
||||
console.log(err);
|
||||
return res.status(400).json({ err: true, msj: "Error al insertar en la base en academico", type: err });
|
||||
})
|
||||
|
||||
} catch (err) {
|
||||
//se deberia borrar el registro anterio de persona;
|
||||
console.log(err);
|
||||
return res.status(400).json({ err: true, msj: "Error al insertar en la base en academico", type: err });
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
res.status(200).json({ error: false, msj: "Exito", id_persona: id_persona });
|
||||
return;
|
||||
}
|
||||
}).catch(async err => {
|
||||
console.log("entro ...", err);
|
||||
|
||||
//se deberia borrar el registro anterio de persona;
|
||||
res.status(400).json({ error: true, msj: "Error al registrar en la base de datos", type: err });
|
||||
return;
|
||||
|
||||
})
|
||||
|
||||
} catch (err) {
|
||||
console.log("afuera ", err);
|
||||
res.status(400).json({ error: true, msj: err });
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = app
|
||||
@@ -0,0 +1,10 @@
|
||||
const connection = require('../conf/connection.js');
|
||||
const express = require('express')
|
||||
var app = express();
|
||||
|
||||
|
||||
app.get('/descargar_cartel', (req, res) => {
|
||||
res.download(__dirname + `/../files/carta_aceptacion-${req.query.id_persona}.docx`);
|
||||
})
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,10 @@
|
||||
const connection = require('../conf/connection.js');
|
||||
const express = require('express')
|
||||
var app = express();
|
||||
|
||||
|
||||
app.get('/descargar_cartel', (req, res) => {
|
||||
res.download(__dirname + `/../files/comprobante_pago-${req.query.id_persona}.docx`);
|
||||
})
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,83 @@
|
||||
const connection = require('../conf/connection.js');
|
||||
const express = require('express');
|
||||
const bcrypt = require('bcrypt');
|
||||
const sendmail = require('sendmail')();
|
||||
|
||||
|
||||
var app = express()
|
||||
var randomstring = require("randomstring");
|
||||
|
||||
function query(consulta) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
connection.query(`${consulta}`, (error, results, files) => {
|
||||
if (error) reject(error);
|
||||
resolve(results);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function depurado(cadena) {
|
||||
if (cadena != null) {
|
||||
cadena = cadena.replace(/'/g, "''");
|
||||
cadena = cadena.replace(/;/g, "m");
|
||||
return cadena;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
app.get('/enviar_email', async(req, res) => {
|
||||
|
||||
let id_persona;
|
||||
try {
|
||||
let n = req.query.correo;
|
||||
console.log(req.query);
|
||||
console.log(req.query, n);
|
||||
n = depurado(n);
|
||||
|
||||
let cad = `select id_persona from persona where correo='${n}'`;
|
||||
let respuesta = await query(cad);
|
||||
console.log("depurado: ", n);
|
||||
console.log("respuesta: ", respuesta);
|
||||
if (respuesta.length == 0)
|
||||
return res.status(400).json({ error: true, msj: "El correo aún no se ha registrado" });
|
||||
else
|
||||
id_persona = respuesta[0].id_persona;
|
||||
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.log("afuera ", err);
|
||||
res.status(400).json({ error: true, msj: "error al verificar el correo" });
|
||||
}
|
||||
try {
|
||||
let nueva = randomstring.generate({
|
||||
length: 10,
|
||||
charset: 'alphanumeric'
|
||||
});
|
||||
let n_pasword = await bcrypt.hash(nueva, 10);
|
||||
|
||||
let cad = `update persona set password='${n_pasword}' where id_persona=${id_persona};`;
|
||||
let respuesta = query(cad);
|
||||
respuesta.then(() => {
|
||||
let correo = req.query.correo;
|
||||
sendmail({
|
||||
from: 'conversatorios.asinea2020@fa.unam.mx',
|
||||
to: `${correo}`,
|
||||
subject: 'Recuperacion de contraseña ASINE',
|
||||
html: `Estimado usuario su nueva contraseña es: ${nueva}`,
|
||||
}, function(err, reply) {
|
||||
console.log(err && err.stack);
|
||||
console.dir(reply);
|
||||
});
|
||||
|
||||
}).catch(() => {
|
||||
return res.status(400).json({ error: true, msj: "error al actualizar la contraseña" });
|
||||
})
|
||||
res.status(200).json({ error: false, msj: "exito" });
|
||||
|
||||
|
||||
} catch (err) {
|
||||
return res.status(400).json({ error: true, msj: "error al encriptar la contraseña" });
|
||||
}
|
||||
})
|
||||
module.exports = app
|
||||
@@ -0,0 +1,11 @@
|
||||
const connection = require('../conf/connection.js');
|
||||
const express = require('express')
|
||||
var app = express();
|
||||
|
||||
|
||||
|
||||
app.get('/get_pdf', (req, res) => {
|
||||
res.download(__dirname + `/../files/lista-${req.query.id_persona}.pdf`);
|
||||
})
|
||||
|
||||
module.exports = app;
|
||||
@@ -1,4 +1,13 @@
|
||||
var express = require('express')
|
||||
var app = express()
|
||||
|
||||
app.use(require('./datos_personales'));
|
||||
app.use(require('./login_persona'));
|
||||
|
||||
app.use(require('./crear_pdf'));
|
||||
|
||||
app.use(require('./get_pdf'));
|
||||
app.use(require('./traer_datos'));
|
||||
app.use(require('./traer_persona'));
|
||||
//app.use(require('./crear_qr'));
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,76 @@
|
||||
const connection = require('../conf/connection.js');
|
||||
const express = require('express');
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
var app = express()
|
||||
|
||||
function query(consulta) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
connection.query(`${consulta}`, (error, results, files) => {
|
||||
if (error) reject(error);
|
||||
resolve(results);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function depurado(cadena) {
|
||||
if (cadena != null) {
|
||||
cadena = cadena.replace(/'/g, "''");
|
||||
cadena = cadena.replace(/;/g, "m");
|
||||
return cadena;
|
||||
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
app.post('/loggin_admin', async(req, res) => {
|
||||
try {
|
||||
let data = req.body;
|
||||
let usuario = depurado(data.usuario);
|
||||
//console.log(usuario, " lksaldksjdlasd");
|
||||
let cad = `select * from admin where usuario='${data.usuario}'`;
|
||||
let respuesta = query(cad);
|
||||
// console.log(respuesta);
|
||||
respuesta.then(async r => {
|
||||
// console.log(r, r.length);
|
||||
if (r.length == 0) {
|
||||
res.status(400).json({ error: false, msj: "Usuario o contraseña invalidos" });
|
||||
return;
|
||||
} else {
|
||||
let pass = data.password;
|
||||
//console.log(pass);
|
||||
let n_pasword = await bcrypt.hash(pass, 10);
|
||||
//console.log(data);
|
||||
// console.log(n_pasword);
|
||||
let ban = bcrypt.compareSync(data.password, r[0].password);
|
||||
if (ban == true) {
|
||||
res.status(200).json({ error: false, msj: "bienvenido", mesa: r[0].nombre_mesa, id_admin: r[0].id_admin });
|
||||
return;
|
||||
} else {
|
||||
res.status(400).json({ error: false, msj: "Usuario o contraseña invalidos" });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}).catch(err => {
|
||||
res.status(400).json({ error: true, msj: err });
|
||||
return;
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.log("afuera ", err);
|
||||
res.status(400).json({ error: true, msj: err });
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = app
|
||||
@@ -0,0 +1,79 @@
|
||||
const connection = require('../conf/connection.js');
|
||||
const express = require('express');
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
var app = express()
|
||||
|
||||
function query(consulta) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
connection.query(`${consulta}`, (error, results, files) => {
|
||||
if (error) reject(error);
|
||||
resolve(results);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function depurado(cadena) {
|
||||
if (cadena != null) {
|
||||
cadena = cadena.replace(/'/g, "''");
|
||||
cadena = cadena.replace(/;/g, "m");
|
||||
return cadena;
|
||||
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
app.post('/login_persona', async(req, res) => {
|
||||
try {
|
||||
let data = req.body;
|
||||
let usuario = depurado(data.correo);
|
||||
//console.log(usuario, " lksaldksjdlasd");
|
||||
console.log(usuario);
|
||||
let cad = `select * from persona where correo='${usuario}';`;
|
||||
console.log(cad);
|
||||
let respuesta = query(cad);
|
||||
// console.log(respuesta);
|
||||
respuesta.then(async r => {
|
||||
// console.log(r, r.length);
|
||||
if (r.length == 0) {
|
||||
res.status(400).json({ error: false, msj: "Usuario o contraseña invalidos" });
|
||||
return;
|
||||
} else {
|
||||
let pass = data.password;
|
||||
//console.log(pass);
|
||||
let n_pasword = await bcrypt.hash(pass, 10);
|
||||
//console.log(data);
|
||||
console.log(n_pasword);
|
||||
let ban = bcrypt.compareSync(data.password, r[0].password);
|
||||
if (ban == true) {
|
||||
|
||||
return res.status(200).json({ error: false, msj: "Bienvenido", data: r[0] });
|
||||
|
||||
} else {
|
||||
res.status(400).json({ error: false, msj: "Usuario o contraseña invalidos" });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}).catch(err => {
|
||||
res.status(400).json({ error: true, msj: err });
|
||||
return;
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.log("afuera ", err);
|
||||
res.status(400).json({ error: true, msj: err });
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = app
|
||||
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
const connection = require('../conf/connection.js');
|
||||
const express = require('express');
|
||||
var qr = require('qr-image');
|
||||
const fs = require('fs');
|
||||
const PDFDocument = require('pdfkit');
|
||||
|
||||
|
||||
|
||||
function query(consulta) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
connection.query(`${consulta}`, (error, results, files) => {
|
||||
if (error) reject(error);
|
||||
resolve(results);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
let c_pdf = function(id_persona) {
|
||||
return new Promise(async function(resolve, reject) {
|
||||
|
||||
let doc = new PDFDocument();
|
||||
|
||||
// let cad = `select * from persona where id_persona=${id_persona}`;
|
||||
// let resp = await query(cad);
|
||||
// let data = resp[var i_m = require('./g_img.js');0];
|
||||
|
||||
|
||||
doc.pipe(fs.createWriteStream(__dirname + `/../files/lista-${id_persona}.pdf`));
|
||||
|
||||
doc.image(qr.imageSync(`${id_persona}`, { type: 'png' }), {
|
||||
fit: [250, 300],
|
||||
align: 'center',
|
||||
valign: 'center'
|
||||
});
|
||||
doc.end();
|
||||
resolve({ "docx": `${id_persona}.pdf` })
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
let g_pdf = async function(idPersona) {
|
||||
|
||||
|
||||
// console.log("datos: ", req.query);
|
||||
let inicio = 120;
|
||||
let id_persona = idPersona;
|
||||
|
||||
|
||||
c_pdf(id_persona)
|
||||
//await doc
|
||||
// .fontSize(25)
|
||||
// .text('Some text with an embedded font!', 100, 100);
|
||||
// await doc.font('Times-Roman')
|
||||
// .fontSize(10)
|
||||
// .text(`${data.nombre} ${ data.apellido_p} ${data.apellido_m}: ${data.id_persona}`, inicio + 60, 40);
|
||||
|
||||
|
||||
//return res.download(__dirname + `/../files/lista-${req.query.id_persona}.pdf`);
|
||||
//return
|
||||
.then(data => {
|
||||
|
||||
//res.download(__dirname + `/../files/comprobante_pago-${req.query.id_persona}.docx`);
|
||||
console.log(data)
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
return;
|
||||
})
|
||||
// console.log(data);
|
||||
|
||||
};
|
||||
|
||||
module.exports = g_pdf;
|
||||
@@ -0,0 +1,103 @@
|
||||
const connection = require('../conf/connection.js');;
|
||||
const express = require('express');
|
||||
const fileUpload = require('express-fileupload');
|
||||
|
||||
|
||||
var app = express()
|
||||
app.use(fileUpload());
|
||||
|
||||
function query(consulta) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
connection.query(`${consulta}`, (error, results, files) => {
|
||||
if (error) reject(error);
|
||||
resolve(results);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function depurado(cadena) {
|
||||
if (cadena != null)
|
||||
return cadena.replace(/'/g, "''");
|
||||
else
|
||||
return null;
|
||||
}
|
||||
app.post('/subir_archivo', async(req, res) => {
|
||||
|
||||
try {
|
||||
console.log(req.files);
|
||||
if (req.files.comprobante_pago != undefined) {
|
||||
let sampleFile = req.files.comprobante_pago;
|
||||
let nombreCortado = sampleFile.name.split('.');
|
||||
let extencion = nombreCortado[nombreCortado.length - 1];
|
||||
let extensionValidas = ['pdf', 'jpg', 'jpeg', 'png'];
|
||||
|
||||
if (extensionValidas.indexOf(extencion) < 0) {
|
||||
return res.status(400).json({
|
||||
error: true,
|
||||
msj: "Extensión invalida del archivo de comprobante_pago"
|
||||
});
|
||||
}
|
||||
}
|
||||
if (req.files.carta_aceptacion != undefined) {
|
||||
|
||||
let sampleFile = req.files.carta_aceptacion;
|
||||
let nombreCortado = sampleFile.name.split('.');
|
||||
let extencion = nombreCortado[nombreCortado.length - 1];
|
||||
let extensionValidas = ['docx', 'doc', 'odt'];
|
||||
|
||||
if (extensionValidas.indexOf(extencion) < 0) {
|
||||
return res.status(400).json({
|
||||
error: true,
|
||||
msj: "Extensión invalida del archivo de carta_aceptacion"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
return res.status(400).json({
|
||||
error: true,
|
||||
msj: "error al verificar la extensión"
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
if (req.files.comprobante_pago != undefined) {
|
||||
let sampleFile = req.files.comprobante_pago;
|
||||
|
||||
sampleFile.mv(`files/comprobante_pago-${req.body.id_persona}.docx`, function(err) {
|
||||
if (err)
|
||||
return res.status(400).json({ error: true, msj: "Error al registrar el cartel" });
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
res.status(400).json({ error: true, msj: "Error al subir el archivo de comprobante_pago", type: err });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
if (req.files.carta_aceptacion != undefined) {
|
||||
let sampleFile = req.files.carta_aceptacion;
|
||||
sampleFile.mv(`files/carta_aceptacion-${req.body.id_persona}.docx`, function(err) {
|
||||
if (err)
|
||||
return res.status(400).json({ error: true, msj: "Error al registrar el carta_aceptacion" });
|
||||
});
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
res.status(400).json({ error: true, msj: "Error al subir el archivo carta de aceptacion", type: err });
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(200).json({ error: false, msj: "exito " });
|
||||
return;
|
||||
|
||||
});
|
||||
|
||||
module.exports = app
|
||||
@@ -0,0 +1,48 @@
|
||||
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('/traer_datos', async(req, res) => {
|
||||
try {
|
||||
let cad = `select nombre from universidad;`;
|
||||
let uni = await query(cad);
|
||||
//console.log(respuesta);
|
||||
|
||||
cad = `select * from evento where tipo_evento='Conversatorio';`;
|
||||
let con = await query(cad);
|
||||
|
||||
cad = `select * from evento where tipo_evento='Taller alumno';`;
|
||||
let t_a = await query(cad);
|
||||
|
||||
|
||||
cad = `select * from evento where tipo_evento='Taller profesor';`;
|
||||
let t_p = await query(cad);
|
||||
|
||||
cad = `select * from evento where tipo_evento='Visitas guiadas';`;
|
||||
let v_g = await query(cad);
|
||||
|
||||
cad = `select * from evento where tipo_evento='Dialogo magistral';`;
|
||||
let d_m = await query(cad);
|
||||
|
||||
res.status(200).json({ error: false, msj: "exito", universidad: uni, conversatorio: con, taller_alumno: t_a, taller_profesor: t_p, visita: v_g, dialogo: d_m });
|
||||
return;
|
||||
} catch (err) {
|
||||
return res.status(400).json({ error: true, msj: "Error al traer los datos" });
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,183 @@
|
||||
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('/traer_persona', async(req, res) => {
|
||||
data = { alumno: [], academico: [] };
|
||||
try {
|
||||
let cad = `select * from persona;`;
|
||||
let r = query(cad);
|
||||
r.then(async(p) => {
|
||||
for (let i = 0; i < p.length; i++) {
|
||||
if (p[i].situacion_academica == 'Alumno') {
|
||||
let aux = {}
|
||||
cad = `select e.*, asi.* from evento as e inner join asistencia as asi where asi.id_persona=${p[i].id_persona} and e.id_evento=asi.id_evento`;
|
||||
|
||||
let n_ans = await query(cad);
|
||||
console.log(p[i]);
|
||||
aux.id_persona = p[i].id_persona;
|
||||
aux.nombre = p[i].nombre;
|
||||
aux.apellido_p = p[i].apellido_p;
|
||||
aux.apellido_m = p[i].apellido_m;
|
||||
aux.comunidad = p[i].comunidad;
|
||||
aux.conversatorio_ponente = 'No';
|
||||
aux.conversatorio_asistente = 'No';
|
||||
aux.taller = 'No';
|
||||
aux.visita = 'No';
|
||||
aux.magistral = 'No';
|
||||
|
||||
|
||||
let ext = true;
|
||||
if (aux.comunidad == 'UNAM')
|
||||
ext = false;
|
||||
|
||||
let tot = 0;
|
||||
for (let j = 0; j < n_ans.length; j++) {
|
||||
|
||||
console.log(aux.nombre, " ", aux.comunidad, " ", tot, " ", ext, " ", n_ans[j].tipo_de_participacion);
|
||||
if (n_ans[j].tipo_evento == 'Conversatorio') {
|
||||
if (n_ans[j].tipo_de_participacion == 'Video') {
|
||||
if (ext == true)
|
||||
tot += 700;
|
||||
else
|
||||
tot += 100;
|
||||
aux.conversatorio_ponente = 'Video: ' + n_ans[j].nombre_evento;
|
||||
|
||||
} else
|
||||
if (n_ans[j].tipo_de_participacion == 'Ensayo') {
|
||||
if (ext == true)
|
||||
tot += 700;
|
||||
else
|
||||
tot += 100;
|
||||
aux.conversatorio_ponente = 'Ensayo: ' + n_ans[j].nombre_evento;
|
||||
} else {
|
||||
aux.conversatorio_asistente = n_ans[j].nombre_evento;
|
||||
if (ext == true)
|
||||
tot += 200;
|
||||
else
|
||||
tot += 100;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (n_ans[j].tipo_evento == 'Taller alumno') {
|
||||
if (ext == true)
|
||||
tot += 900;
|
||||
else
|
||||
tot += 200;
|
||||
aux.taller = n_ans[j].nombre_evento;
|
||||
|
||||
|
||||
}
|
||||
if (n_ans[j].tipo_evento == 'Visitas guiadas') {
|
||||
if (ext == true)
|
||||
tot += 500;
|
||||
else
|
||||
tot += 500;
|
||||
aux.visita = n_ans[j].nombre_evento;
|
||||
|
||||
}
|
||||
if (n_ans[j].tipo_evento == 'Dialogo magistral') {
|
||||
aux.magistral = n_ans[j].nombre_evento;
|
||||
}
|
||||
aux.pago = tot;
|
||||
|
||||
}
|
||||
|
||||
data.alumno.push(aux);
|
||||
console.log(" ");
|
||||
console.log(" ");
|
||||
}
|
||||
if (p[i].situacion_academica == 'Académico') {
|
||||
let aux = {}
|
||||
cad = `select e.*, asi.* from evento as e inner join asistencia as asi where asi.id_persona=${p[i].id_persona} and e.id_evento=asi.id_evento`;
|
||||
|
||||
let n_ans = await query(cad);
|
||||
aux.id_persona = p[i].id_persona;
|
||||
aux.nombre = p[i].nombre;
|
||||
aux.apellido_p = p[i].apellido_p;
|
||||
aux.apellido_m = p[i].apellido_m;
|
||||
aux.comunidad = p[i].comunidad;
|
||||
aux.conversatorio_ponente = 'No';
|
||||
aux.conversatorio_asistente = 'No';
|
||||
aux.taller = 'No';
|
||||
aux.visita = 'No';
|
||||
aux.magistral = 'No';
|
||||
|
||||
let tot = 0;
|
||||
let ext = true;
|
||||
if (aux.comunidad == 'UNAM')
|
||||
ext = false;
|
||||
|
||||
|
||||
for (let j = 0; j < n_ans.length; j++) {
|
||||
if (n_ans[j].tipo_evento == 'Conversatorio') {
|
||||
|
||||
if (n_ans[j].tipo_de_participacion == 'Ponente') {
|
||||
if (ext == true)
|
||||
tot += 1000;
|
||||
else
|
||||
tot += 500;
|
||||
aux.conversatorio_ponente = n_ans[j].nombre_event;
|
||||
|
||||
} else {
|
||||
aux.conversatorio_asistente = n_ans[j].nombre_evento;
|
||||
if (ext == true)
|
||||
tot += 1300;
|
||||
else
|
||||
tot += 650;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (n_ans[j].tipo_evento == 'Taller profesor') {
|
||||
if (ext == true)
|
||||
tot += 1500;
|
||||
else
|
||||
tot += 750;
|
||||
aux.taller = n_ans[j].nombre_evento;
|
||||
|
||||
|
||||
}
|
||||
if (n_ans[j].tipo_evento == 'Visitas guiadas') {
|
||||
if (ext == true)
|
||||
tot += 500;
|
||||
else
|
||||
tot += 500;
|
||||
aux.visita = n_ans[j].nombre_evento;
|
||||
|
||||
}
|
||||
if (n_ans[j].tipo_evento == 'Dialogo magistral') {
|
||||
aux.magistral = n_ans[j].nombre_evento;
|
||||
}
|
||||
aux.pago = tot;
|
||||
|
||||
}
|
||||
|
||||
data.academico.push(aux);
|
||||
}
|
||||
}
|
||||
console.log(p);
|
||||
res.status(200).json({ error: false, datos: data });
|
||||
})
|
||||
|
||||
} catch (err) {
|
||||
return res.status(400).json({ error: true, msj: "Error al traer los datos" });
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
Reference in New Issue
Block a user