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){
|
switch(_updateType){
|
||||||
case "withdraw":
|
case "withdraw":
|
||||||
// Code here to withdraw funds
|
// 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;
|
break;
|
||||||
case "deposit":
|
case "deposit":
|
||||||
// Code here to withdraw funds
|
// 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;
|
break;
|
||||||
default:
|
default:
|
||||||
log.ERROR('Update type not valid: ', _updateType);
|
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);
|
if(!sqlQuery) return callback(new Error("SQL Query empty"), undefined);
|
||||||
|
|
||||||
|
log.DEBUG("Updating Balance with SQL Query: ", sqlQuery);
|
||||||
|
|
||||||
runSQL(sqlQuery, this.connection, (err, rows) => {
|
runSQL(sqlQuery, this.connection, (err, rows) => {
|
||||||
if (err) return callback(err, undefined);
|
if (err) return callback(err, undefined);
|
||||||
if (rows?.affectedRows > 0) return callback(undefined, rows);
|
if (!rows?.affectedRows > 0) return callback(new Error("Error updating Balance", rows), undefined);
|
||||||
return callback(undefined, undefined);
|
return callback(undefined, rows);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user