-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 'delete-user' to remove a user definitely - 'list-balances' to show the balances of all the users
- Loading branch information
Showing
6 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const path = require('path'); | ||
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') }); | ||
const { connectWithTimeout, askQuestion, silentExit } = require('./helpers'); | ||
const User = require('~/models/User'); | ||
|
||
(async () => { | ||
await connectWithTimeout(); | ||
|
||
/** | ||
* Show the welcome / help menu | ||
*/ | ||
console.purple('---------------'); | ||
console.purple('Deleting a user'); | ||
console.purple('---------------'); | ||
|
||
let email = ''; | ||
if (process.argv.length >= 3) { | ||
email = process.argv[2]; | ||
} else { | ||
email = await askQuestion('Email:'); | ||
} | ||
let user = await User.findOne({ email: email }); | ||
if (user !== null) { | ||
if ((await askQuestion(`Delete user ${user}?`)) === 'y') { | ||
user = await User.findOneAndDelete({ _id: user._id }); | ||
if (user !== null) { | ||
console.yellow(`Deleted user ${user}`); | ||
} else { | ||
console.yellow(`Couldn't delete user with email ${email}`); | ||
} | ||
} | ||
} else { | ||
console.yellow(`Didn't find user with email ${email}`); | ||
} | ||
|
||
silentExit(0); | ||
})(); | ||
|
||
process.on('uncaughtException', (err) => { | ||
if (!err.message.includes('fetch failed')) { | ||
console.error('There was an uncaught error:'); | ||
console.error(err); | ||
} | ||
|
||
if (!err.message.includes('fetch failed')) { | ||
process.exit(1); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const path = require('path'); | ||
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') }); | ||
const { connectWithTimeout, silentExit } = require('./helpers'); | ||
const Balance = require('~/models/Balance'); | ||
const User = require('~/models/User'); | ||
|
||
(async () => { | ||
await connectWithTimeout(); | ||
|
||
/** | ||
* Show the welcome / help menu | ||
*/ | ||
console.purple('-----------------------------'); | ||
console.purple('Show the balance of all users'); | ||
console.purple('-----------------------------'); | ||
|
||
let users = await User.find({}); | ||
for (const user of users) { | ||
let balance = await Balance.findOne({ user: user._id }); | ||
if (balance !== null) { | ||
console.green(`User ${user.name} has a balance of ${balance.tokenCredits}`); | ||
} else { | ||
console.yellow(`User ${user.name} has no balance`); | ||
} | ||
} | ||
|
||
silentExit(0); | ||
})(); | ||
|
||
process.on('uncaughtException', (err) => { | ||
if (!err.message.includes('fetch failed')) { | ||
console.error('There was an uncaught error:'); | ||
console.error(err); | ||
} | ||
|
||
if (!err.message.includes('fetch failed')) { | ||
process.exit(1); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters