diff --git a/src/database/consultas.js b/src/database/consultas.js index fab65fe..9a81f2a 100644 --- a/src/database/consultas.js +++ b/src/database/consultas.js @@ -110,4 +110,27 @@ async function getEventosDiscoteca(discotecaId){ } } -module.exports.getEventosDiscoteca = getEventosDiscoteca; \ No newline at end of file +module.exports.getEventosDiscoteca = getEventosDiscoteca; + + + +async function addReserva(reserva){ + try{ + let conn = await mariadb.getConn(); + var rows = await conn.query("SELECT * FROM reserva WHERE UserID = ? AND eventoID = ?", [reserva.userID, reserva.eventoID]); + if(!rows){ //primero inserta en la tabla codigo, y luego en la tabla reserva + reserva.codigoUnicoID = await conn.query("INSERT INTO codigo (UserID, codigo, numReservas) VALUES (?, ?, ?)", + [reserva.userID, reserva.codigo, reserva.numReservas]); + rows = await conn.query("INSERT INTO reserva (UserID, EventoID, codigoUnicoID, codigoDescuento, descuentoPorciento) VALUES (?, ?, ?, ?, ?)", + [reserva.userID, reserva.eventoID, reserva.codigoUnicoID, reserva.codigoDescuento, reserva.descuentoPorciento]); + return rows; + } + else{ + console.log("Ya hay una reserva para este evento."); + } + }catch(err){ + console.log("No se pudo acceder a la BD: "+err);} +} + +module.exports.addReserva = addReserva; + diff --git a/src/routes/rutas.js b/src/routes/rutas.js index 45003ca..5ab454d 100644 --- a/src/routes/rutas.js +++ b/src/routes/rutas.js @@ -55,7 +55,6 @@ router.get('/evento', async function(req, res){ }) - router.post('/eventosDiscoteca', async function(req, res){ console.log(req.body); const evento = req.body; @@ -66,4 +65,6 @@ router.post('/eventosDiscoteca', async function(req, res){ } }) + + module.exports = router; \ No newline at end of file