From 207b7461b0b6c595960f94987e23db0a9ed07733 Mon Sep 17 00:00:00 2001 From: onsaliyo Date: Sat, 3 Apr 2021 11:41:38 +0200 Subject: [PATCH] get para eventos --- src/database/consultas.js | 19 +++++++++++++++++-- src/routes/rutas.js | 10 +++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/database/consultas.js b/src/database/consultas.js index aa39721..3c16de1 100644 --- a/src/database/consultas.js +++ b/src/database/consultas.js @@ -72,7 +72,22 @@ async function addEvento(evento){ module.exports.addEvento = addEvento; -async function getEventos(discotecaId){ +async function getEventos(){ + try{ + let conn = await mariadb.getConn(); + const rows = await conn.query("SELECT id, discotecaID, nombre, localizacion, fecha, hora, descripcion, precio1, precio2 FROM evento"); + conn.release(); + + if(rows){ + return rows;} + }catch(err){ + console.log("No se pudo acceder a la BD: "+err); + } +} + +module.exports.getEventos = getEventos; + +async function getEventosDiscoteca(discotecaId){ try{ let conn = await mariadb.getConn(); const rows = await conn.query("SELECT id, discotecaID, nombre, localizacion, fecha, hora, descripcion, precio1, precio2 FROM evento WHERE discotecaID = ?", [discotecaId.id]); @@ -86,4 +101,4 @@ async function getEventos(discotecaId){ } } -module.exports.getEventos = getEventos; \ No newline at end of file +module.exports.getEventosDiscoteca = getEventosDiscoteca; \ No newline at end of file diff --git a/src/routes/rutas.js b/src/routes/rutas.js index 0ad81d4..45003ca 100644 --- a/src/routes/rutas.js +++ b/src/routes/rutas.js @@ -46,12 +46,20 @@ router.post('/evento', async function(req, res){ } }) +router.get('/evento', async function(req, res){ + var eventosout = await consultasDB.getEventos(); + res.setHeader('Content-Type', 'application/json'); + if (eventosout){ + res.send(JSON.stringify(eventosout)); + } +}) + router.post('/eventosDiscoteca', async function(req, res){ console.log(req.body); const evento = req.body; - eventout = await consultasDB.getEventos(evento); + eventout = await consultasDB.getEventosDiscoteca(evento); if (eventout){ console.log(JSON.stringify(eventout)); res.send(JSON.stringify(eventout));