Fixed bug in transactions
- all balances would get updated from transaction
This commit is contained in:
@@ -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);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user