incluida consulta de anadir reservas a la BD

This commit is contained in:
onsaliyo 2021-05-18 16:50:00 +02:00
parent f9d2e17756
commit 4baccd5dbf
2 changed files with 26 additions and 2 deletions

View File

@ -111,3 +111,26 @@ async function getEventosDiscoteca(discotecaId){
} }
module.exports.getEventosDiscoteca = getEventosDiscoteca; 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;

View File

@ -55,7 +55,6 @@ router.get('/evento', async function(req, res){
}) })
router.post('/eventosDiscoteca', async function(req, res){ router.post('/eventosDiscoteca', async function(req, res){
console.log(req.body); console.log(req.body);
const evento = req.body; const evento = req.body;
@ -66,4 +65,6 @@ router.post('/eventosDiscoteca', async function(req, res){
} }
}) })
module.exports = router; module.exports = router;