-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestions.js
More file actions
146 lines (134 loc) · 4.03 KB
/
questions.js
File metadata and controls
146 lines (134 loc) · 4.03 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const db = require('./db/db'); //import database
const inquirer = require('inquirer'); //import inquirer
// main menu
const mainMenu = [
{
type: 'list',
name: 'task',
message: 'What would you like to do?',
choices: ['View all departments', 'View all roles', 'View all employees', 'Add a department', 'Add a role', 'Add an employee', 'Update an employee role', new inquirer.Separator(), 'Quit']
},
];
// questions to add new department
const departmentQuestions = [
{
type: 'input',
name: 'department',
message: 'What is the name of the department you want to add?'
},
];
// questions to add new role
const roleQuestions = [
{
type: 'input',
name: 'role',
message: 'What is the name of the role you want to add?'
},
{
type: 'input',
name: 'salary',
message: 'What is the salary of the role?'
},
{
type: 'list',
name: 'newRoleDepartment',
message: 'Which department does the role belong to?',
choices: async () => {
const [result] = await db.findAllDepartments(); // await function call
// create new array for every department
const selection = result.map(item => {
return {
value: item.id,
name: item.name
};
});
return selection;
},
},
];
// questions to add new employee
const employeeQuestions = [
{
type: 'input',
name: 'firstname',
message: "What is the employee's first name?"
},
{
type: 'input',
name: 'lastname',
message: "What is the employee's last name?"
},
{
type: 'list',
name: 'employeeRole',
message: "What is the employee's role?",
choices: async () => {
const [result] = await db.findAllRoles();
// create new array for every role
const selection = result.map(item => {
return {
value: item.id,
name: item.title
};
});
return selection;
},
},
{
type: 'list',
name: 'manager',
message: "Who's the employee's manager?",
choices: async () => {
const [result] = await db.findAllEmployees();
// presents only employess who are managers
const filter = result.filter(item => {
return item.manager == null;
});
// create new array for every employee
const selection = filter.map(item => {
return {
value: item.id,
name: item.first_name + " " + item.last_name
};
});
return selection;
},
},
];
// questions to update role
const updateRoleQuestions = [
{
type: 'list',
name: 'emUpdate',
message: "Which employee's role do you want to update?",
choices: async () => {
const [result] = await db.findAllEmployees();
// create new array for every employee
const selection = result.map(item => {
return {
value: item.id,
name: item.first_name + " " + item.last_name
};
});
return selection;
},
},
{
type: 'list',
name: 'emRoleUpdate',
message: "Which role do you want to assign the selected employee?",
choices: async () => {
const [result] = await db.findAllRoles();
// create new array for every role
const selection = result.map(item => {
return {
value: item.id,
name: item.title
};
});
return selection;
},
},
];
// export main menu and questions
module.exports = { mainMenu, departmentQuestions, roleQuestions, employeeQuestions, updateRoleQuestions };