Skip to content

Commit 63626b1

Browse files
committed
refactor(bin): eliminate var and use template string refactor string things
Signed-off-by: Erona <[email protected]>
1 parent 2f82e0c commit 63626b1

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

bin/manage_users

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,44 @@ Usage: bin/manage_users [--pass password] (--add | --del) user-email
2424

2525
// Using an async function to be able to use await inside
2626
async function createUser(argv) {
27-
var existing_user = await models.User.findOne({where: {email: argv["add"]}});
27+
const existing_user = await models.User.findOne({where: {email: argv["add"]}});
2828
// Cannot create already-existing users
2929
if(existing_user != undefined) {
30-
console.log("User with e-mail "+existing_user.email+" already exists! Aborting ...");
30+
console.log(`User with e-mail ${existing_user.email} already exists! Aborting ...`);
3131
process.exit(1);
3232
}
3333

3434
// Find whether we use cmdline or prompt password
35+
let pass;
3536
if(argv["pass"] == undefined) {
36-
var pass = readline.question("Password for "+argv["add"]+":", {hideEchoBack: true});
37+
pass = readline.question(`Password for ${argv["add"]}:`, {hideEchoBack: true});
3738
} else {
3839
console.log("Using password from commandline...");
39-
var pass = "" + argv["pass"];
40+
pass = "" + argv["pass"];
4041
}
4142

4243
// Lets try to create, and check success
43-
var ref = await models.User.create({email: argv["add"], password: pass});
44+
const ref = await models.User.create({email: argv["add"], password: pass});
4445
if(ref == undefined) {
45-
console.log("Could not create user with email "+argv["add"]);
46+
console.log(`Could not create user with email ${argv["add"]}`);
4647
process.exit(1);
4748
} else
48-
console.log("Created user with email "+argv["add"]);
49+
console.log(`Created user with email ${argv["add"]}`);
4950
}
5051

5152
// Using an async function to be able to use await inside
5253
async function deleteUser(argv) {
5354
// Cannot delete non-existing users
54-
var existing_user = await models.User.findOne({where: {email: argv["del"]}});
55-
if(existing_user == undefined) {
56-
console.log("User with e-mail "+argv["del"]+" does not exist, cannot delete");
55+
const existing_user = await models.User.findOne({where: {email: argv["del"]}});
56+
if(existing_user === undefined) {
57+
console.log(`User with e-mail ${argv["del"]} does not exist, cannot delete`);
5758
process.exit(1);
5859
}
5960

6061
// Sadly .destroy() does not return any success value with all
6162
// backends. See sequelize #4124
6263
await existing_user.destroy();
63-
console.log("Deleted user "+argv["del"]+" ...");
64+
console.log(`Deleted user ${argv["del"]} ...`);
6465
}
6566

6667
var options = {
@@ -69,11 +70,11 @@ var options = {
6970
};
7071

7172
// Perform commandline-parsing
72-
var argv = minimist(process.argv.slice(2));
73+
const argv = minimist(process.argv.slice(2));
7374

74-
var keys = Object.keys(options);
75-
var opts = keys.filter((key) => argv[key] !== undefined);
76-
var action = opts[0];
75+
const keys = Object.keys(options);
76+
const opts = keys.filter((key) => argv[key] !== undefined);
77+
const action = opts[0];
7778

7879
// Check for options missing
7980
if (opts.length === 0) {

0 commit comments

Comments
 (0)