Skip to content

Commit

Permalink
Show current balance before updating
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis531 committed Oct 23, 2024
1 parent 23fde30 commit 253327f
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions config/set-balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ const Balance = require('~/models/Balance');
silentExit(1);
}

if (!amount) {
amount = await askQuestion('amount:');
}
// Validate the amount
if (!amount) {
console.red('Error: Please specify an amount!');
silentExit(1);
}

// Validate the user
const user = await User.findOne({ email }).lean();
if (!user) {
Expand All @@ -74,6 +65,22 @@ const Balance = require('~/models/Balance');
console.purple(`Found user: ${user.email}`);
}

let balance = await Balance.findOne({ user: user._id }).lean();
if (!balance) {
console.purple('User has no balance!');
} else {
console.purple(`Current Balance: ${balance.tokenCredits}`);
}

if (!amount) {
amount = await askQuestion('amount:');
}
// Validate the amount
if (!amount) {
console.red('Error: Please specify an amount!');
silentExit(1);
}

/**
* Now that we have all the variables we need, lets set the balance
*/
Expand Down

0 comments on commit 253327f

Please sign in to comment.