gestionado completamente hacer una reserva (no testeado)

This commit is contained in:
onsaliyo 2021-05-19 17:17:27 +02:00
parent 4baccd5dbf
commit fd4dde725f
2 changed files with 28 additions and 1 deletions

View File

@ -132,5 +132,23 @@ async function addReserva(reserva){
console.log("No se pudo acceder a la BD: "+err);} console.log("No se pudo acceder a la BD: "+err);}
} }
module.exports.addReserva = addReserva; 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;

View File

@ -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; module.exports = router;