Check for falsy existing_user variable. Fixes #234

Use another return code for "User already exist"
This allows external scripts to differentiate between failure reasons.

Signed-off-by: Soeren Wegener <wegener92@gmail.com>
This commit is contained in:
Soeren Wegener 2019-12-09 17:41:11 +01:00
parent 33150b79c7
commit bb1c150698
No known key found for this signature in database
GPG key ID: 1CA5723999CABD50

View file

@ -36,9 +36,9 @@ function getPass(argv, action) {
async function createUser(argv) {
const existing_user = await models.User.findOne({where: {email: argv["add"]}});
// Cannot create already-existing users
if(existing_user != undefined) {
if(existing_user) {
console.log(`User with e-mail ${existing_user.email} already exists! Aborting ...`);
process.exit(1);
process.exit(2);
}
const pass = getPass(argv, "add");
@ -57,7 +57,7 @@ async function createUser(argv) {
async function deleteUser(argv) {
// Cannot delete non-existing users
const existing_user = await models.User.findOne({where: {email: argv["del"]}});
if(existing_user === undefined) {
if(!existing_user) {
console.log(`User with e-mail ${argv["del"]} does not exist, cannot delete`);
process.exit(1);
}
@ -73,7 +73,7 @@ async function deleteUser(argv) {
async function resetUser(argv) {
const existing_user = await models.User.findOne({where: {email: argv["reset"]}});
// Cannot reset non-existing users
if(existing_user == undefined) {
if(!existing_user) {
console.log(`User with e-mail ${argv["reset"]} does not exist, cannot reset`);
process.exit(1);
}