From 284cdd2776066d208d65a560a9a3838934e32999 Mon Sep 17 00:00:00 2001 From: onsaliyo Date: Thu, 27 May 2021 20:08:20 +0200 Subject: [PATCH] connection release en todas las consultas --- src/database/consultas.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/database/consultas.js b/src/database/consultas.js index b392e23..e3cfdd9 100644 --- a/src/database/consultas.js +++ b/src/database/consultas.js @@ -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; +