-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (35 loc) · 1.1 KB
/
index.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
import { getUsers, getUserById, addUser, updateUser, deleteUser } from "./models.js";
import { createUserObject, createUpdateUserObject } from "./utils/createUserObject.js";
import { handleError } from "./utils/handleError.js";
import { help } from "./utils/help.js"
const args = process.argv.splice(2);
const action = args[0];
switch (action) {
case "list":
console.log(getUsers(process.env.PATH_FILE_USER));
break;
case "search":
console.log(getUserById(args[1]));
break;
case "add":
const newUser = createUserObject(args);
console.log(addUser(newUser));
break;
case "update":
const updateUser = createUpdateUserObject(args);
console.log(updateUser(updateUser));
break;
case "delete":
console.log(deleteUser(args[1]));
break;
case "help":
console.log(help());
break;
default:
const error = handleError(
new Error("Invalid command, use 'help' for assistance"),
process.env.PATH_FILE_ERROR
);
console.log(error);
break;
}