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

@@ -36,8 +36,8 @@ exports.createAccount = (_discordAccountId, callback) => {
})
}
exports.withdrawBalance = async (_withdrawAmount, _accountId, callback) => {
userStorage.updateBalance('withdraw', _withdrawAmount, _accountId, async (err, result) => {
exports.withdrawBalance = async (_withdrawAmount, _discordAccountId, callback) => {
userStorage.updateBalance('withdraw', _withdrawAmount, _discordAccountId, async (err, result) => {
if (err) return callback(err, undefined);
if(result) return callback(undefined, result);
@@ -55,6 +55,22 @@ exports.verifyBalance = (_tokensToBeUsed, _accountId, callback) => {
return callback(undefined, true);
})
}
/**
* Check the given account for the token balance
*
* @param {*} _discordAccountId
* @param {*} callback
*/
exports.checkBalance = (_discordAccountId, callback) => {
if (!_discordAccountId) return callback(new Error("No discord account given to check balance of"), undefined);
userStorage.getRecordBy("discord_account_id", _discordAccountId, (err, accountRecord) => {
if (err) return callback(err, undefined);
if (!accountRecord) return callback(new Error("No account record given"), undefined);
return callback(undefined, accountRecord.balance);
})
}
exports.insufficientTokensResponse = (interaction) => {
log.DEBUG("INSUFFICIENT TOKENS RESPONSE")