From 4b7b4e19a7b791a79d7abee4acaf8e6b1858a95b Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 26 Feb 2023 12:52:09 -0500 Subject: [PATCH] Fixed bug in transactions - all balances would get updated from transaction --- libStorage.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libStorage.js b/libStorage.js index 1ce3cb7..f554e79 100644 --- a/libStorage.js +++ b/libStorage.js @@ -202,11 +202,11 @@ exports.UserStorage = class UserStorage extends Storage { switch(_updateType){ case "withdraw": // Code here to withdraw funds - sqlQuery = `UPDATE ${this.dbTable} SET balance=balance-${_updateAmount};`; + sqlQuery = `UPDATE ${this.dbTable} SET balance=balance-${_updateAmount} WHERE discord_account_id = ${_account_id};`; break; case "deposit": // Code here to withdraw funds - sqlQuery = `UPDATE ${this.dbTable} SET balance=balance+${_updateAmount};`; + sqlQuery = `UPDATE ${this.dbTable} SET balance=balance+${_updateAmount} WHERE discord_account_id = ${_account_id};`; break; default: log.ERROR('Update type not valid: ', _updateType); @@ -215,10 +215,12 @@ exports.UserStorage = class UserStorage extends Storage { if(!sqlQuery) return callback(new Error("SQL Query empty"), undefined); + log.DEBUG("Updating Balance with SQL Query: ", sqlQuery); + runSQL(sqlQuery, this.connection, (err, rows) => { if (err) return callback(err, undefined); - if (rows?.affectedRows > 0) return callback(undefined, rows); - return callback(undefined, undefined); + if (!rows?.affectedRows > 0) return callback(new Error("Error updating Balance", rows), undefined); + return callback(undefined, rows); }) } }