Add balance command for users to check their balance

This commit is contained in:
Logan Cusano
2023-02-26 21:42:37 -05:00
parent 94aa9b4a32
commit 7bddccc5f4
4 changed files with 65 additions and 9 deletions

View File

@@ -177,14 +177,26 @@ exports.UserStorage = class UserStorage extends Storage {
})
}
/**
* Check or return the balance of a given account ID
*
* @param {*} _tokensToBeUsed The amount of tokens to be used, set to 0 to return the balance
* @param {*} _account_id The account ID to check or return the balance of
* @param {*} callback
*/
checkBalance(_tokensToBeUsed, _account_id, callback) {
if (!_account_id) return callback(new Error("Account not specified when checking account balance"), undefined);
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);
if (record?.balance && record.balance > _tokensToBeUsed) return callback(undefined, true);
else{
return callback(undefined, false);
// Check to see if the account has a balance greater than what was given
if(_tokensToBeUsed > 0){
if (record?.balance && record.balance > _tokensToBeUsed) return callback(undefined, true);
else return callback(undefined, false);
}
return callback(undefined, record.balance)
})
}
@@ -193,11 +205,11 @@ exports.UserStorage = class UserStorage extends Storage {
*
* @param {string} _updateType The type of update to make to the account [ withdraw | deposit ]
* @param {number} _updateAmount The amount to update the account
* @param {number} _account_id The ID of the account to update
* @param {number} _account_id The ID of the discord account to update
* @param {function} callback The callback function to call with the results
* @returns Result from the SQL query or false
*/
updateBalance(_updateType, _updateAmount, _account_id, callback){
updateBalance(_updateType, _updateAmount, _discord_account_id, callback){
var sqlQuery = "";
switch(_updateType){
case "withdraw":