diff --git a/src/database/consultas.js b/src/database/consultas.js index 9a81f2a..b454317 100644 --- a/src/database/consultas.js +++ b/src/database/consultas.js @@ -132,5 +132,23 @@ async function addReserva(reserva){ console.log("No se pudo acceder a la BD: "+err);} } + + module.exports.addReserva = addReserva; +async function comprobarDescuento(reserva){ + try{ + let conn = await mariadb.getConn(); + const evento = await conn.query("SELECT * FROM evento WHERE id = ?", [reserva.eventoID]); + if(evento.tipoDescuento){ + const porciento = await conn.query("SELECT porciento FROM descuentos WHERE id = ?", [evento.tipoDescuento]); + return porciento; + } + else return null; + }catch(err){ + console.log("No se pudo acceder a la BD: "+err); + } + +} + +module.exports.comprobarDescuento = comprobarDescuento; diff --git a/src/routes/rutas.js b/src/routes/rutas.js index 5ab454d..e372084 100644 --- a/src/routes/rutas.js +++ b/src/routes/rutas.js @@ -65,6 +65,15 @@ router.post('/eventosDiscoteca', async function(req, res){ } }) - +router.post('/reserva', async function (req, res){ + console.log(req.body); + const reserva = req.body; + reserva.descuentoPorciento = await consultasDB.comprobarDescuento(reserva); + reservaConfirmada = await consultasDB.addReserva(reserva); + if (reservaConfirmada){ + console.log(JSON.stringify(reservaConfirmada)); + res.send(JSON.stringify(reservaConfirmada)); + } +}) module.exports = router; \ No newline at end of file