diff --git a/.env b/.env new file mode 100644 index 0000000..7f95a44 --- /dev/null +++ b/.env @@ -0,0 +1,11 @@ +DB_HOST_RED_INVESTIGACION = 'localhost' +DB_USER_RED_INVESTIGACION = 'root' +DB_PASS_RED_INVESTIGACION = 'georgechido' +DB_NAME_RED_INVESTIGACION = 'red_de_investigacion' +PORT= 3000 + + +DB_HOST_PROFESORES = '132.248.80.194' +DB_USER_PROFESORES = 'des_george' +DB_PASS_PROFESORES = 'emp140 ' +DB_NAME_PROFESORES = 'Betelgeuse_dat_prof' \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..323ba1b --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +DB_HOST_RED_INVESTIGACION = '132.248.80.194' +DB_USER_RED_INVESTIGACION = 'usr_red_de_investigacion' +DB_PASS_RED_INVESTIGACION = 'Inv3st1G4' +DB_NAME_RED_INVESTIGACION = 'P_orion_red_de_investigacion' +PORT= 3000 + + +DB_HOST_PROFESORES = '132.248.80.194' +DB_USER_PROFESORES = 'des_george' +DB_PASS_PROFESORES = 'emp140 ' +DB_NAME_PROFESORES = 'Betelgeuse_dat_prof' \ No newline at end of file diff --git a/app.js b/app.js index 03bf59c..3f224ef 100644 --- a/app.js +++ b/app.js @@ -1,14 +1,19 @@ -var express = require('express'); -var app = express(); -var cors = require('cors'); -app.use(cors()); -app.get('/', function(req, res) { - res.send('that is works'); -}); +const express = require('express') +const app = express(); +const cors = require('cors') -app.use(express.json()) // for parsing application/json +require('dotenv').config() + +app.get('/', function(req, res) { + res.send('Api de red de investigacion') +}) + +app.use(cors()) +app.use(express.json()) app.use(express.urlencoded({ extended: true })) app.use(require('./routes/index.js')) -app.listen(3062, function() { - console.log('Example app listening on port 3062!'); -}); \ No newline at end of file + + +app.listen(process.env.PORT, () => { + console.log('Api escuchando el puerto', process.env.PORT) +}) \ No newline at end of file diff --git a/conf/baseProfesoresDSC.js b/conf/baseProfesoresDSC.js index 20afad3..4f8a66f 100644 --- a/conf/baseProfesoresDSC.js +++ b/conf/baseProfesoresDSC.js @@ -1,18 +1,18 @@ var mysql = require('mysql') const mysqlConnection = mysql.createConnection({ - host: '132.248.80.194', - user: 'des_george', - database: 'Betelgeuse_dat_prof', - password: 'emp140 ' + host: process.env.DB_HOST_PROFESORES, + user: process.env.DB_USER_PROFESORES, + password: process.env.DB_PASS_PROFESORES, + database: process.env.DB_NAME_PROFESORES }) mysqlConnection.connect((err) => { if (err) { - console.log('No se pudo conectar a la base') + console.log('No se pudo conectar a la base de datos de profesores') console.log(err) } - else console.log('base conectada') + else console.log('Base de profesores conectada') }) diff --git a/conf/connection.js b/conf/connection.js index 0fc9268..cf27e80 100644 --- a/conf/connection.js +++ b/conf/connection.js @@ -1,32 +1,18 @@ var mysql = require('mysql'); -const connection = mysql.createConnection({ - host: '132.248.80.194', - user: 'usr_red_de_investigacion', - password: 'Inv3st1G4', - database: 'P_orion_red_de_investigacion' +const mysqlConnection = mysql.createConnection({ + host: process.env.DB_HOST_RED_INVESTIGACION, + user: process.env.DB_USER_RED_INVESTIGACION, + password: process.env.DB_PASS_RED_INVESTIGACION, + database: process.env.DB_NAME_RED_INVESTIGACION }); -module.exports = connection; +mysqlConnection.connect((err) => { + if (err) { + console.log('No se pudo conectar a la base de Red de investigacion') + console.log(err) + } + else console.log('Base de Red de investigacion conectada') +}) - -// usr_red_de_investigacion -// Inv3st1G4 - - - - -// var mysql = require('mysql'); -// const connection = mysql.createConnection({ -// host: '132.248.80.194', -// user: 'usr_red_de_investigacion', -// password: 'Inv3st1G4', -// database: 'P_orion_red_de_investigacion' -// }); - -// module.exports = connection; - - - -// usr_red_de_investigacion -// Inv3st1G4 \ No newline at end of file +module.exports = mysqlConnection diff --git a/conf/sistemas.js b/conf/sistemas.js index e5a45d5..7148476 100644 --- a/conf/sistemas.js +++ b/conf/sistemas.js @@ -1,9 +1,9 @@ -var mysql = require('mysql'); -const connection = mysql.createConnection({ - host: '132.248.180.228', - user: 'USR_REDINVESTIGACION', - database: 'BASESDSI', - password: '67NHA*Y' -}); +// var mysql = require('mysql'); +// const connection = mysql.createConnection({ +// host: '132.248.180.228', +// user: 'USR_REDINVESTIGACION', +// database: 'BASESDSI', +// password: '67NHA*Y' +// }); -module.exports = connection; \ No newline at end of file +// module.exports = connection; \ No newline at end of file diff --git a/data_base/values.sql b/data_base/values.sql index d158d18..2f25503 100644 --- a/data_base/values.sql +++ b/data_base/values.sql @@ -1,6 +1,6 @@ insert into usuario values(null, "UIM_User", "$2b$10$wjy7AE.5r0KY83llKguY4e51cvyl643IdNnCGeaOnJ/IwoBJdoKsS"); -- Red_Investigacion_UiM* -insert into usuario values(null, `cedetec_User`, "$2b$10$9UYHmMoTBjnB736dS7/Eleygisp0tIVuMPv5XhMuNMfzdjk3YjFcK"); +insert into usuario values(null, "cedetec_User", "$2b$10$9UYHmMoTBjnB736dS7/Eleygisp0tIVuMPv5XhMuNMfzdjk3YjFcK"); -- cedetec_red_* @@ -28,7 +28,7 @@ insert into entidades values(null, "Otra facultad de la UNAM"); insert into entidades values(null, "Otra universidad de Mexico"); insert into entidades values (null, "Universidad en el extrajero"); -insert into entidades values (null, "Asociaciín civil"); +insert into entidades values (null, "Asociación civil"); insert into entidades values (null, "Dependencia federal"); insert into entidades values (null, "Dependencia municipal"); insert into entidades values (null, "Otra entidad"); diff --git a/package-lock.json b/package-lock.json index a784c50..b6c9276 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "bcrypt": "^3.0.7", "cors": "^2.8.5", + "dotenv": "^10.0.0", "express": "^4.17.1", "mssql": "^6.0.1", "mysql": "^2.18.1", @@ -846,6 +847,14 @@ "resolved": "https://registry.npmjs.org/dfa/-/dfa-1.2.0.tgz", "integrity": "sha512-ED3jP8saaweFTjeGX8HQPjeC1YYyZs98jGNZx6IiBvxW7JG5v492kamAQB3m2wop07CvU/RQmzcKr6bgcC5D/Q==" }, + "node_modules/dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "engines": { + "node": ">=10" + } + }, "node_modules/duplexer2": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz", @@ -3792,6 +3801,11 @@ "resolved": "https://registry.npmjs.org/dfa/-/dfa-1.2.0.tgz", "integrity": "sha512-ED3jP8saaweFTjeGX8HQPjeC1YYyZs98jGNZx6IiBvxW7JG5v492kamAQB3m2wop07CvU/RQmzcKr6bgcC5D/Q==" }, + "dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==" + }, "duplexer2": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz", diff --git a/package.json b/package.json index fe508b0..0ae450c 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "dependencies": { "bcrypt": "^3.0.7", "cors": "^2.8.5", + "dotenv": "^10.0.0", "express": "^4.17.1", "mssql": "^6.0.1", "mysql": "^2.18.1", diff --git a/public/comprobante-5.pdf b/public/comprobante-5.pdf index 9463642..a2519f2 100755 Binary files a/public/comprobante-5.pdf and b/public/comprobante-5.pdf differ diff --git a/public/comprobante-7.pdf b/public/comprobante-7.pdf index 5e29c5d..02c5cdf 100644 Binary files a/public/comprobante-7.pdf and b/public/comprobante-7.pdf differ diff --git a/routes/busca_profesor.js b/routes/busca_profesor.js index d8fb920..935127f 100644 --- a/routes/busca_profesor.js +++ b/routes/busca_profesor.js @@ -41,9 +41,17 @@ app.get('/busca_profesor', async(req, res) => { try{ let getProfesoresQuery = `SELECT * FROM Profesor;` let getProfesoresResponse = await query(getProfesoresQuery).then(getProfesoresResponse =>{ - console.log(getProfesoresResponse) - res.status(200).json({error: false, msj: 'Exito al obtener la respuesta', data: getProfesoresResponse}) - return + let diferentsRfcDicctionary = {} + let profesorData = [] + getProfesoresResponse.map(profesor =>{ + if(typeof diferentsRfcDicctionary[profesor.RFC] === 'undefined'){ + profesorData.push(profesor) + diferentsRfcDicctionary[profesor.RFC] = 'true' + } + }) + + res.status(200).json({error: false, msj: 'Exito al obtener la respuesta', data: profesorData}) + return }).catch(err =>{ console.log(err) res.status(400).json({error: false, msj: 'Ocurrio un error al traer los datos del profesor', desc: err}) diff --git a/routes/datos_proyecto_1.js b/routes/datos_proyecto_1.js index 640f85b..a585da4 100644 --- a/routes/datos_proyecto_1.js +++ b/routes/datos_proyecto_1.js @@ -30,7 +30,7 @@ app.post('/datos_proyecto_1', async(req, res) => { if (req.body.nombre_proyecto == undefined || req.body.rfc == undefined || req.body.nombre_responsable == undefined || req.body.disciplina == undefined || req.body.objetivo_general == undefined || req.body.campo_conocimiento == undefined || req.body.linea_investigacion == undefined || req.body.objetivo_particular == undefined) { - res.status(400).json({ error: true, msj: 'No estan los datos que requiere la appi' }); + res.status(400).json({ error: true, msj: 'No estan los datos que requiere la Api' }); return; } diff --git a/routes/pdf.js b/routes/pdf.js index e129fc1..8ba8c42 100644 --- a/routes/pdf.js +++ b/routes/pdf.js @@ -7,14 +7,9 @@ const express = require('express'); var app = express(); const sql = require('mssql') -function query(consulta) { - return new Promise(function(resolve, reject) { - connection.query(`${consulta}`, (error, results, files) => { - if (error) reject(error); - resolve(results); - }); - }) -} +const queryBdProfesores = require('./sqlQuery/queryBdProfesores') +const query = require('./sqlQuery/queryBdRedInvestigacion') + @@ -24,12 +19,8 @@ let g_pdf = async function hacer(id_proyecto) { const doc = new PDFDocument({ size: 'A4' }); doc.pipe(fs.createWriteStream(__dirname + `/../public/comprobante-${id}.pdf`)); - - console.log("el id proyetco en pdf= ", id); - - let inicio = 120; var datetime = new Date(); var anio = new Date(); @@ -75,23 +66,29 @@ let g_pdf = async function hacer(id_proyecto) { doc.font('Times-Roman').moveDown().fontSize(10).text(`Nombre del profesor: ${ datos.nombre_responsable }`, sang); try { - let pass = "67NHA*Y"; - // make sure that any items are correctly URL encoded in the connection string - await sql.connect(`mssql://USR_REDINVESTIGACION:${pass}@132.248.180.228/DB_ARES`) - const result = await sql.query `EXEC DB_ARES.dbo.SPD_CONSULTA_DATOS_X_PROFESOR_RED_INVESTIGACION ${datos.rfc_responsable};` - // console.log("sss"); - // console.log(result.recordsets); - console.log("datos ", datos.rfc_responsable, ' ', result.recordsets[0][0]); - let base = result.recordsets[0][0]; - doc.font('Times-Roman').moveDown().fontSize(10).text(`Numero de trabajador: ${ base.Numero_Trabajador } RFC: ${ base.Rfc }`, sang); - doc.font('Times-Roman').moveDown().fontSize(10).text(`Categoria: ${ base.Categoria }`, sang); - doc.font('Times-Roman').moveDown().fontSize(10).text(`Adscripcion: ${ base.Adscripcion }`, sang); - doc.font('Times-Roman').moveDown().fontSize(10).text(`Nivel maximo de estudios: ${ base['Nivel maximo de estudios'] }`, sang); - doc.font('Times-Roman').moveDown().fontSize(10).text(`Telefono de oficina: ${ base['Tel. oficina'] } Extensión: ${ base['Extensión'] }`, sang); - doc.font('Times-Roman').moveDown().fontSize(10).text(`Telefono particular: ${ base.Particular } Celular: ${ base.Celular }`, sang); - doc.font('Times-Roman').moveDown().fontSize(10).text(`Correo institucional: ${ base['Correo Institucional'] } `, sang); - doc.font('Times-Roman').moveDown().fontSize(10).text(`Correo personal: ${ base['Correo Personal'] } `, sang); - doc.font('Times-Roman').moveDown().fontSize(10).text(`Espacio fisico: ${ base.EspacioFisico } Edificio: ${base.Edificio}`, sang); + // let pass = "67NHA*Y"; + // codigo comentado porque anteriormente se hacia esta coneccion con anabel + // await sql.connect(`mssql://USR_REDINVESTIGACION:${pass}@132.248.180.228/DB_ARES`) + // const result = await sql.query `EXEC DB_ARES.dbo.SPD_CONSULTA_DATOS_X_PROFESOR_RED_INVESTIGACION ${datos.rfc_responsable};` + //console.log("datos ", datos.rfc_responsable, ' ', result.recordsets[0][0]); + //let base = result.recordsets[0][0]; + + + let queryGetProfesor = `SELECT * FROM Profesor WHERE RFC='${datos.rfc_responsable}';` + let responseGetProfesor = await queryBdProfesores(queryGetProfesor) + console.log(datos.rfc_responsable) + responseGetProfesor = responseGetProfesor[0] + + + doc.font('Times-Roman').moveDown().fontSize(10).text(`Numero de trabajador: ${ responseGetProfesor.NumTrabajador } RFC: ${ responseGetProfesor.RFC }`, sang); + doc.font('Times-Roman').moveDown().fontSize(10).text(`Categoria: ${ responseGetProfesor.Nombramiento }`, sang); + doc.font('Times-Roman').moveDown().fontSize(10).text(`Adscripcion: ${ responseGetProfesor.Adscripcion }`, sang); + doc.font('Times-Roman').moveDown().fontSize(10).text(`Nivel maximo de estudios: ${ responseGetProfesor.GradoMaximo }`, sang); + doc.font('Times-Roman').moveDown().fontSize(10).text(`Telefono de oficina: ${ responseGetProfesor.TelOficina } Extensión: ${ responseGetProfesor.Extension }`, sang); + doc.font('Times-Roman').moveDown().fontSize(10).text(`Telefono particular: ${ responseGetProfesor.Particular } Celular: ${ responseGetProfesor.Celular }`, sang); + doc.font('Times-Roman').moveDown().fontSize(10).text(`Correo institucional: ${ responseGetProfesor.CorreoInstitucional } `, sang); + doc.font('Times-Roman').moveDown().fontSize(10).text(`Correo personal: ${ responseGetProfesor.CorreoPersonal } `, sang); + doc.font('Times-Roman').moveDown().fontSize(10).text(`Espacio fisico: ${ responseGetProfesor.EspacioFisico } Edificio: ${responseGetProfesor.Edificio}`, sang); } catch (err) { console.log(err); @@ -339,6 +336,6 @@ let g_pdf = async function hacer(id_proyecto) { doc.end(); - return "acabo papa"; + return } module.exports = g_pdf; \ No newline at end of file diff --git a/routes/sqlQuery/queryBdRedInvestigacion.js b/routes/sqlQuery/queryBdRedInvestigacion.js new file mode 100644 index 0000000..f5de14e --- /dev/null +++ b/routes/sqlQuery/queryBdRedInvestigacion.js @@ -0,0 +1,12 @@ +const connection = require('../../conf/connection') + +function query(consulta) { + return new Promise(function(resolve, reject) { + connection.query(`${consulta}`, (error, results, files) => { + if (error) reject(error); + resolve(results); + }); + }) +} + +module.exports = query \ No newline at end of file