Fixed bug in transactions

- all balances would get updated from transaction
This commit is contained in:
Logan Cusano
2023-02-26 12:52:09 -05:00
parent dd0a64aff0
commit 4b7b4e19a7

View File

@@ -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);
})
}
}