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