-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.js
66 lines (62 loc) · 1.36 KB
/
menu.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import prompts from "prompts";
import User from "./user";
import Department from "./department";
const MENU = () => {
return [
{
type: "select",
name: "menu",
message: "What can I do for you?",
choices: [
{ title: "User management", value: "1" },
{ title: "Department management", value: "2" }
]
},
{
type: "select",
name: "submenu",
message: "And?",
choices: prev =>
prev === "1"
? [
{ title: "Create user", value: "11" },
{ title: "Delete user", value: "12" }
]
: [
{ title: "Create department", value: "21" },
{ title: "Delete department", value: "22" }
]
}
];
};
class Menu {
async start() {
const qs = MENU();
const res = await prompts(qs);
let user;
let department;
const { menu, submenu } = res || {};
if (menu === "1") {
user = new User();
} else {
department = new Department();
}
switch (submenu) {
case "11":
user.create();
return false;
case "12":
user.delete();
return false;
case "21":
department.create();
return false;
case "22":
department.delete();
return false;
default:
return false;
}
}
}
export default Menu;