2
2
const Interface = require ( './Interface' ) ;
3
3
const inquirer = require ( 'inquirer' ) ;
4
4
inquirer . registerPrompt ( 'search-list' , require ( 'inquirer-search-list' ) ) ;
5
- const artwork = require ( 'ascii-art ' ) ;
5
+ const cTable = require ( 'console.table ' ) ;
6
6
7
7
const queryInterface = new Interface ( ) ;
8
8
9
9
class CommandLinePrompts {
10
10
constructor ( ) {
11
-
11
+ //used by printTable method
12
+ this . printValues = [
13
+ //example according to console.table README
14
+ //['name', 'age'],
15
+ //['max', 20],
16
+ //['joe', 30]
17
+ ] ;
12
18
}
13
19
14
20
optionMenu ( ) {
@@ -59,8 +65,19 @@ class CommandLinePrompts {
59
65
}
60
66
61
67
viewDepartments ( ) {
68
+
69
+ console . log ( `
70
+ =======================================
71
+ Viewing All Departments
72
+ =======================================
73
+ ` ) ;
74
+
62
75
queryInterface . allDepartments ( )
63
- . then ( ( ) => {
76
+ . then ( ( rows ) => {
77
+ //print db data from query
78
+ this . printValues = rows ;
79
+ this . printTable ( ) ;
80
+
64
81
inquirer . prompt ( {
65
82
type : 'confirm' ,
66
83
name : 'userChoice' ,
@@ -77,8 +94,19 @@ class CommandLinePrompts {
77
94
}
78
95
79
96
viewRoles ( ) {
97
+
98
+ console . log ( `
99
+ =======================================
100
+ Viewing All Roles
101
+ =======================================
102
+ ` ) ;
103
+
80
104
queryInterface . allRoles ( )
81
- . then ( ( ) => {
105
+ . then ( ( rows ) => {
106
+ //print db data from query
107
+ this . printValues = rows ;
108
+ this . printTable ( ) ;
109
+
82
110
inquirer . prompt ( {
83
111
type : 'confirm' ,
84
112
name : 'userChoice' ,
@@ -95,8 +123,19 @@ class CommandLinePrompts {
95
123
}
96
124
97
125
viewEmployees ( ) {
126
+
127
+ console . log ( `
128
+ =======================================
129
+ Viewing All Employees
130
+ =======================================
131
+ ` ) ;
132
+
98
133
queryInterface . allEmployees ( )
99
- . then ( ( ) => {
134
+ . then ( ( rows ) => {
135
+ //print db data from query
136
+ this . printValues = rows ;
137
+ this . printTable ( ) ;
138
+
100
139
inquirer . prompt ( {
101
140
type : 'confirm' ,
102
141
name : 'userChoice' ,
@@ -113,6 +152,13 @@ class CommandLinePrompts {
113
152
}
114
153
115
154
addDepartmentMenu ( ) {
155
+
156
+ console . log ( `
157
+ =======================================
158
+ Add a Department
159
+ =======================================
160
+ ` ) ;
161
+
116
162
inquirer . prompt (
117
163
{
118
164
type : 'input' ,
@@ -148,14 +194,21 @@ class CommandLinePrompts {
148
194
}
149
195
150
196
addRoleMenu ( ) {
197
+
198
+ console . log ( `
199
+ =======================================
200
+ Add a Role
201
+ =======================================
202
+ ` ) ;
203
+
151
204
queryInterface . allDepartments ( )
152
205
. then ( RowDataPacket => {
153
206
//valid RowDataPacket conversion solution #1
154
207
//let packetObj = Object.assign({}, RowDataPacket);
155
208
//valid RowDataPacket conversion solution #2
156
209
const packetArr = Array . from ( RowDataPacket ) ;
157
210
//console.log(packetObj);
158
- console . log ( packetArr ) ;
211
+ // console.log(packetArr);
159
212
160
213
const departmentNamesArr = packetArr . map ( packet => {
161
214
return packet . name ;
@@ -182,7 +235,7 @@ class CommandLinePrompts {
182
235
validate : salary => {
183
236
let salaryInt = Number . parseInt ( salary ) ;
184
237
185
- console . log ( salaryInt ) ;
238
+ // console.log(salaryInt);
186
239
187
240
if ( ! salaryInt || salaryInt === NaN ) {
188
241
console . log ( "Please enter a salary value!" ) ;
@@ -203,9 +256,9 @@ class CommandLinePrompts {
203
256
}
204
257
] )
205
258
. then ( ( answers ) => {
206
- console . log ( answers ) ;
259
+ // console.log(answers);
207
260
answers . salary = Number . parseFloat ( answers . salary ) . toFixed ( 2 ) ;
208
- console . log ( answers ) ;
261
+ // console.log(answers);
209
262
const updatedRole = {
210
263
title : answers . role ,
211
264
salary : Number . parseFloat ( answers . salary ) . toFixed ( 2 ) ,
@@ -221,7 +274,7 @@ class CommandLinePrompts {
221
274
//package up the data to send to the db
222
275
updatedRole . department_id = packetFound [ 0 ] . id . toString ( ) ;
223
276
224
- console . log ( updatedRole ) ;
277
+ // console.log(updatedRole);
225
278
226
279
queryInterface . addRole ( updatedRole )
227
280
. then ( ( ) => {
@@ -243,6 +296,13 @@ class CommandLinePrompts {
243
296
}
244
297
245
298
addEmployeeMenu ( ) {
299
+
300
+ console . log ( `
301
+ =======================================
302
+ Add an Employee
303
+ =======================================
304
+ ` ) ;
305
+
246
306
queryInterface . allEmployees ( )
247
307
. then ( RowDataPacketEmployees => {
248
308
//valid RowDataPacket conversion solution #2
@@ -257,7 +317,7 @@ class CommandLinePrompts {
257
317
} ) . map ( manager => {
258
318
return manager . Employee ;
259
319
} ) ;
260
- console . log ( managerNamesArr ) ;
320
+ // console.log(managerNamesArr);
261
321
262
322
queryInterface . allRoles ( )
263
323
. then ( RowDataPacketRoles => {
@@ -267,7 +327,7 @@ class CommandLinePrompts {
267
327
const rolesArr = rolesPacketArr . map ( role => {
268
328
return role . title ;
269
329
} ) ;
270
- console . log ( rolesArr ) ;
330
+ // console.log(rolesArr);
271
331
272
332
inquirer . prompt ( [
273
333
{
@@ -312,7 +372,7 @@ class CommandLinePrompts {
312
372
] )
313
373
. then ( ( answers ) => {
314
374
315
- console . log ( answers ) ;
375
+ // console.log(answers);
316
376
317
377
const newEmployee = {
318
378
first_name : answers . first_name ,
@@ -332,18 +392,19 @@ class CommandLinePrompts {
332
392
return packet . id ;
333
393
}
334
394
} ) ;
335
-
395
+ //package up the data to send to the db
396
+ newEmployee . manager_id = manager [ 0 ] . id . toString ( ) ;
397
+ }
336
398
let role = rolesPacketArr . filter ( packet => {
337
399
if ( answers . role === packet . title ) {
338
400
return packet . id ;
339
401
}
340
402
} ) ;
403
+
341
404
//package up the data to send to the db
342
- newEmployee . manager_id = manager [ 0 ] . id . toString ( ) ;
343
405
newEmployee . role_id = role [ 0 ] . id . toString ( ) ;
344
- }
345
406
346
- console . log ( newEmployee ) ;
407
+ // console.log(newEmployee);
347
408
348
409
queryInterface . addEmployee ( newEmployee )
349
410
. then ( ( ) => {
@@ -366,6 +427,13 @@ class CommandLinePrompts {
366
427
}
367
428
368
429
updateEmployeeRoleMenu ( ) {
430
+
431
+ console . log ( `
432
+ =======================================
433
+ Update an Employee's Role
434
+ =======================================
435
+ ` ) ;
436
+
369
437
queryInterface . allEmployees ( )
370
438
. then ( RowDataPacketEmployees => {
371
439
//valid RowDataPacket conversion solution #2
@@ -375,7 +443,7 @@ class CommandLinePrompts {
375
443
return employee . Employee ;
376
444
} ) ;
377
445
378
- console . log ( employeeNamesArr ) ;
446
+ // console.log(employeeNamesArr);
379
447
380
448
queryInterface . allRoles ( )
381
449
. then ( RowDataPacketRoles => {
@@ -385,7 +453,7 @@ class CommandLinePrompts {
385
453
const rolesArr = rolesPacketArr . map ( role => {
386
454
return role . title ;
387
455
} ) ;
388
- console . log ( rolesArr ) ;
456
+ // console.log(rolesArr);
389
457
390
458
inquirer . prompt ( [
391
459
{
@@ -403,7 +471,7 @@ class CommandLinePrompts {
403
471
404
472
] )
405
473
. then ( ( answers ) => {
406
- console . log ( answers ) ;
474
+ // console.log(answers);
407
475
408
476
const updatedEmployee = {
409
477
id : '' ,
@@ -426,7 +494,7 @@ class CommandLinePrompts {
426
494
updatedEmployee . id = employee [ 0 ] . id . toString ( ) ;
427
495
updatedEmployee . role_id = role [ 0 ] . id . toString ( ) ;
428
496
429
- console . log ( updatedEmployee ) ;
497
+ // console.log(updatedEmployee);
430
498
431
499
queryInterface . updateRole ( updatedEmployee )
432
500
. then ( ( ) => {
@@ -449,6 +517,9 @@ class CommandLinePrompts {
449
517
450
518
} ) ;
451
519
}
520
+ printTable ( ) {
521
+ console . table ( this . printValues ) ;
522
+ }
452
523
}
453
524
454
525
module . exports = CommandLinePrompts ;
0 commit comments