Large Transaction Update

This commit is contained in:
Logan Cusano
2023-02-27 00:20:54 -05:00
parent 0c4fee091e
commit 384dd7011f
6 changed files with 79 additions and 31 deletions

View File

@@ -186,6 +186,7 @@ exports.UserStorage = class UserStorage extends Storage {
*/
checkBalance(_tokensToBeUsed, _account_id, callback) {
if (!_account_id) return callback(new Error("Account not specified when checking account balance"), undefined);
log.DEBUG("Tokens to verify against balance", _tokensToBeUsed, _account_id);
if (!_tokensToBeUsed && !_tokensToBeUsed >= 0) return callback(new Error("Specified tokens are invalid when checking account balance"), undefined);
this.getRecordBy('account_id', _account_id, (err, record) => {
if (err) return callback(err, undefined);
@@ -214,11 +215,11 @@ exports.UserStorage = class UserStorage extends Storage {
switch(_updateType){
case "withdraw":
// Code here to withdraw funds
sqlQuery = `UPDATE ${this.dbTable} SET balance=balance-${_updateAmount} WHERE discord_account_id = ${_account_id};`;
sqlQuery = `UPDATE ${this.dbTable} SET balance=balance-${_updateAmount} WHERE discord_account_id = ${_discord_account_id};`;
break;
case "deposit":
// Code here to withdraw funds
sqlQuery = `UPDATE ${this.dbTable} SET balance=balance+${_updateAmount} WHERE discord_account_id = ${_account_id};`;
sqlQuery = `UPDATE ${this.dbTable} SET balance=balance+${_updateAmount} WHERE discord_account_id = ${_discord_account_id};`;
break;
default:
log.ERROR('Update type not valid: ', _updateType);