diff --git a/example.env b/example.env new file mode 100644 index 0000000..321d209 --- /dev/null +++ b/example.env @@ -0,0 +1,5 @@ +HOSTDB = +USERDB = +PASSDB = +DB = +PORT = \ No newline at end of file diff --git a/routes/registro.js b/routes/registro.js index 0f905c7..3b105f1 100644 --- a/routes/registro.js +++ b/routes/registro.js @@ -10,9 +10,16 @@ var app = express() function query(consulta) { return new Promise(function(resolve, reject) { connection.query(`${consulta}`, (error, results, files) => { - //connection.end(); - if (error)reject(error); + if (error){ + + reject(error); + + + } + resolve(results); + + console.log("si pasa por aqui"); }); }) @@ -38,7 +45,7 @@ function depurado(cadena) { // } app.post('/registro', async(req, res) => { - console.log("entro"); + let body = req.body; let idEquipo = 1; @@ -49,32 +56,34 @@ app.post('/registro', async(req, res) => { let cad = `SELECT * FROM Persona WHERE correo='${n_correo}' AND lider = true;`; let respuesta = await query(cad); if (respuesta.length != 0) { - + console.log( "El correo del lider ya fue registrado anteriormente"); res.status(400).json({ error: false, msj: "El correo del lider ya fue registrado anteriormente" }); return; } } catch(error){ + connection.end(); let men = `Errror al buscar el correo ${error}`; console.log(men); res.status(400).json({ error: true, msj: men }); - throw new typeofError (error); + throw new TypeError (error); } try{ - let cad = `INSERT INTO Equipo VALUES (null, '${body.desafio}', '${body.campus}', ${body.numeroIntegrantes});`; + let cad = `INSERT INTO Equipo VALUES (null, '${body.nombreEqui}', '${body.desafio}', '${body.campus}', ${body.numeroIntegrantes});`; await query(cad); cad = `SELECT COUNT(*) FROM Equipo;`; let ans = await query(cad); console.log(`respuesta: ${ans}`); } catch(error){ + connection.end(); let men = `Error al registar Equipo ${error}`; console.log(men); res.status(400).json({ error: true, msj: men }); - throw new typeofError (error); + throw new TypeError (error); } // CREATE TABLE `Persona` ( // `idPersona` integer PRIMARY KEY NOT NULL AUTO_INCREMENT, @@ -99,63 +108,66 @@ app.post('/registro', async(req, res) => { await query(cad); } catch(error){ + connection.end(); let men = `Error al registar Integrantes ${error}` console.log(men); res.status(400).json({ error: true, msj: men }); - throw new typeofError (error); + throw new TypeError (error); } - try{ - var nodemailer = require('nodemailer'); + // try{ + // var nodemailer = require('nodemailer'); - var transporter = nodemailer.createTransport({ - service: 'gmail', - auth: { - user: 'daniel.adrian.ramirez.george@gmail.com', - pass: '753951852_dan' - } - }); + // var transporter = nodemailer.createTransport({ + // service: 'gmail', + // auth: { + // user: 'daniel.adrian.ramirez.george@gmail.com', + // pass: '753951852_dan' + // } + // }); - var mailOptions = { - from: `daniel.adrian.ramirez.george@gmail.com`, - to: `${body.correoLider}`, - subject: 'Registro HACKATHON VIRTUAL', - text: `Tu registro se ha realizado de manera correcta es importante que considere el equipo la asistencia a las siguientes actividades - Primer Taller: Julio 14   - Segundo Taller: Julio 16 - Tercer Taller: Julio 22 - Cuarto Taller: Julio 28 - Hackathon: Agosgto 1-2 + // var mailOptions = { + // from: `daniel.adrian.ramirez.george@gmail.com`, + // to: `${body.correoLider}`, + // subject: 'Registro HACKATHON VIRTUAL', + // text: `Tu registro se ha realizado de manera correcta es importante que considere el equipo la asistencia a las siguientes actividades + // Primer Taller: Julio 14   + // Segundo Taller: Julio 16 + // Tercer Taller: Julio 22 + // Cuarto Taller: Julio 28 + // Hackathon: Agosgto 1-2 - Una vez inscrito, se compartirán más detalles.` - }; + // Una vez inscrito, se compartirán más detalles.` + // }; - await transporter.sendMail(mailOptions, function(error, info){ - if (error) { - let men = `Error al enviar mensaje: ${error}`; - console.log(men); - res.status(400).json({ error: true, msj: men }); - throw new typeofError (error); + // await transporter.sendMail(mailOptions, function(error, info){ + // if (error) { + // let men = `Error al enviar mensaje: ${error}`; + // console.log(men); + // res.status(400).json({ error: true, msj: men }); + // throw new TypeError (error); - } else { + // } else { - console.log('Email sent: ' + info.response); - res.status(200).json({ error: false, msj: "exito"}); - - return; + // console.log('Email sent: ' + info.response); + // res.status(200).json({ error: false, msj: "exito"}); + // return; - } - }); - } - catch(error){ - let men = `Error al enviar mensaje: ${error}`; - console.log(men); - res.status(400).json({ error: true, msj: men }); - throw new typeofError (error); + // } + // }); + // } + // catch(error){ + // let men = `Error al enviar mensaje: ${error}`; + // console.log(men); + // res.status(400).json({ error: true, msj: men }); + // throw new TypeError (error); - } + // } + res.status(200).json({ error: false, msj: "exito"}); + connection.end(); + return; diff --git a/sql/script.sql b/sql/script.sql index e1a0ca2..eec5660 100644 --- a/sql/script.sql +++ b/sql/script.sql @@ -1,5 +1,9 @@ +drop database hackDB; +CREATE database hackDB; +use hackDB CREATE TABLE `Equipo` ( `idEquipo` integer PRIMARY KEY NOT NULL AUTO_INCREMENT, + `nombre` varchar(100), `desafio` varchar(100), `campus` varchar(100), `numeroIntegrantes` varchar(100)