blob: 276e63451a78cde67fd0c5af562670e771e3a6e3 (
plain) (
blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#!/usr/bin/env node
require("dotenv").config();
const db = require("./db");
const fs = require("fs").promises;
const params = process.argv.slice(2);
let idx;
if ((idx = params.indexOf("-r")) > -1) {
// DB management
const param = params[idx + 1];
switch (param) {
case "all":
db.resetAll()
.then(() => console.info("Regenerated everything!"))
.then(() => process.exit(0))
.catch(console.error);
break;
case "motto":
db.resetMottovote()
.then(() => console.info("Reset motto voting!"))
.then(() => process.exit(0))
.catch(console.error);
break;
case "poll":
db.resetPolls()
.then(() => console.info("Reset polls!"))
.then(() => process.exit(0))
.catch(console.error);
break;
case "profile":
db.resetProfiles()
.then(() => console.info("Reset profiles!"))
.then(() => process.exit(0))
.catch(console.error);
break;
case "quotes":
db.resetQuotes()
.then(() => console.info("Reset quotes!"))
.then(() => process.exit(0))
.catch(console.error);
break;
case "secrets":
db.resetSecrets()
.then(() => console.info("Reset secrets!"))
.then(() => process.exit(0))
.catch(console.error);
break;
case "questions":
db.resetQuestions()
.then(() => console.info("Reset questions!"))
.then(() => process.exit(0))
.catch(console.error);
break;
case "char":
db.resetCharacteristics()
.then(() => console.info("Reset char!"))
.then(() => process.exit(0))
.catch(console.error);
break;
default:
console.info("Nothing to do!");
process.exit(0);
break;
}
} else if ((idx = params.indexOf("-U")) > -1) {
// Update management (e.g.: add new poll options)
const param = params[idx + 1];
if (!param) process.exit(1);
switch (param) {
case "all":
console.info("Updating motto votes, polls and profile!");
db.initMottovote()
.then(() => console.info("Updating motto votes!"))
.then(() => db.initPolls())
.then(() => console.info("Updating polls!"))
.then(() => db.initProfiles())
.then(() => console.info("Updating profile!"))
.then(() => db.initQuestions())
.then(() => process.exit(0))
.catch(console.error);
break;
case "motto":
db.initMottovote()
.then(() => console.info("Updating motto votes!"))
.then(() => process.exit(0))
.catch(console.error);
break;
case "poll":
db.initPolls()
.then(() => console.info("Updating polls!"))
.then(() => process.exit(0))
.catch(console.error);
break;
case "profile":
db.initProfiles()
.then(() => console.info("Updating profile!"))
.then(() => process.exit(0))
.catch(console.error);
break;
case "questions":
db.initQuestions()
.then(() => console.info("Updating questions!"))
.then(() => process.exit(0))
.catch(console.error);
break;
default:
console.info("Nothing to do!");
process.exit(0);
break;
}
} else if ((idx = params.indexOf("--user")) > -1) {
// User management (e.g.: Regen user pwd)
const uid = params[idx + 1];
if (!uid) process.exit(1);
db.regenerateUser(uid)
.then((pwd) => console.info(`Regenerating user with id ${uid}: ${pwd}`))
.then(() => process.exit(0))
.catch(console.error);
} else {
console.log("Nothing to do!");
process.exit(0);
}
|