From c660b72738a98a354922528bdb1c23f076828759 Mon Sep 17 00:00:00 2001 From: onsaliyo Date: Thu, 3 Jun 2021 18:24:35 +0200 Subject: [PATCH] obtencion de los codigos de un usuario --- src/database/consultas.js | 17 +++++++++++++++++ src/routes/rutas.js | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/src/database/consultas.js b/src/database/consultas.js index e3cfdd9..2929ce1 100644 --- a/src/database/consultas.js +++ b/src/database/consultas.js @@ -201,3 +201,20 @@ async function activarCodigo(reserva){ module.exports.activarCodigo = activarCodigo; +async function getCodigos(usuario){ + try{ + let conn = await mariadb.getConn(); + const codigos = await conn.query("SELECT * FROM codigo WHERE UserID = ?", [usuario.userID]); + conn.release(); + if(codigos.length>0){ + return codigos; + } + else return null; + + }catch(err){ + console.log("No se pudo acceder a la BD: "+err); +} + + + + diff --git a/src/routes/rutas.js b/src/routes/rutas.js index f9e035d..4111a08 100644 --- a/src/routes/rutas.js +++ b/src/routes/rutas.js @@ -78,4 +78,12 @@ router.post('/reserva', async function (req, res){ } }) +router.post('/codigosUsuario', async function(req, res){ + const usuario = req.body; + const codigos = await consultasDB.getCodigos(usuario); + console.log(JSON.stringify.codigos); + res.send(JSON.stringify.codigos); + +}) + module.exports = router; \ No newline at end of file