forked from danny-avila/LibreChat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete-user.js
49 lines (43 loc) · 1.25 KB
/
delete-user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const path = require('path');
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
const { askQuestion, silentExit } = require('./helpers');
const User = require('~/models/User');
const connect = require('./connect');
(async () => {
await connect();
/**
* 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);
}
});