mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00

* Refactoring opening of DB to config/helpers.js * Adding two user scripts: - 'delete-user' to remove a user definitely - 'list-balances' to show the balances of all the users
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
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);
|
|
}
|
|
});
|