connection release en todas las consultas

This commit is contained in:
onsaliyo 2021-05-27 20:08:20 +02:00
parent 35f83c91ad
commit 284cdd2776
1 changed files with 10 additions and 3 deletions

View File

@ -41,7 +41,6 @@ async function getDiscoteca(discotecaId){
let conn = await mariadb.getConn();
const rows = await conn.query("SELECT discotecaID, nombre, telefono, localizacion FROM discoteca WHERE discotecaID = ?", [discotecaId]);
conn.release();
if (rows){
return rows;}
@ -57,7 +56,6 @@ async function addEvento(evento){
try{
let conn = await mariadb.getConn();
var rows = await conn.query ("SELECT * FROM evento WHERE id = ?", [evento.id]);
conn.release();
if (!rows.length>0){
rows = await conn.query
("INSERT INTO evento (discotecaID, nombre, localizacion, fecha, hora, descripcion, precio1, precio2) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
@ -134,10 +132,12 @@ async function addReserva(reserva){
[reserva.UserID, reserva.EventoID, reserva.codigoUnicoID, reserva.codigoDescuento]);
}
await conn.query("UPDATE codigo SET numReservas = numReservas + 1 WHERE codigo = ?", [reserva.codigoDescuento]);
conn.release();
return reserva;
}
else{
console.log("Ya hay una reserva para este evento.");
conn.release();
}
}catch(err){
console.log("No se pudo acceder a la BD: "+err);}
@ -154,9 +154,13 @@ async function comprobarDescuento(reserva){
const tipoDescuento = evento[0].tipoDescuento;
if(tipoDescuento){
const porciento = await conn.query("SELECT porciento FROM descuentos WHERE id = ?", [tipoDescuento]);
conn.release();
return porciento[0].porciento;
}
else return 0;
else{
conn.release();
return 0;
}
}catch(err){
console.log("No se pudo acceder a la BD: "+err);
}
@ -170,9 +174,11 @@ async function activarCodigo(reserva){
try{
let conn = await mariadb.getConn();
const codigo = await conn.query("SELECT id FROM codigo WHERE codigo = ?", [reserva.codigoDescuento]);
conn.release();
console.log(codigo);
if (codigo.length>0){
const reservaOriginal = await conn.query("SELECT EventoID FROM reserva WHERE codigoUnicoID = ?", [codigo[0].id]);
conn.release();
console.log(reservaOriginal);
if (reservaOriginal[0].EventoID == reserva.EventoID){
console.log("Codigo válido");
@ -194,3 +200,4 @@ async function activarCodigo(reserva){
}
module.exports.activarCodigo = activarCodigo;