-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds master prompt function and showTable function
- Loading branch information
Showing
3 changed files
with
68 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,87 @@ | ||
//include everything needed to run our app | ||
const inquirer = require('inquirer'); | ||
const mysql = require('mysql2'); | ||
const cTable = require('console.table'); | ||
require('dotenv').config(); | ||
|
||
//establish connection w/mysql2 | ||
const connection = mysql.createConnection( { | ||
host: 'localhost', | ||
user: process.env.DB_USER, | ||
database: process.env.DB_NAME, | ||
password: process.env.DB_PASSWORD | ||
}); | ||
|
||
connection.connect((err) => { | ||
if (err) throw err; | ||
console.log('Connected!'); | ||
}); | ||
|
||
// define the set of primary options to display to the user while navigating the app in the terminal. | ||
//greet the user with some goddamn hospitality and show 'em around the place | ||
console.log('\x1b[35m welcome to HR Simulator 42!! \x1b[0m'); //using \x1b escape char for colored console logs | ||
console.log('\x1b[33m ready to feel like an HR god? \x1b[0m'); | ||
// list of basic choices for viewing and adding | ||
const options = [ | ||
{ | ||
value: "view all departments", | ||
}, | ||
{ | ||
value: "view all roles", | ||
}, | ||
{ | ||
value: "view all employees", | ||
}, | ||
{ | ||
value: "add a department", | ||
value: "department", | ||
}, | ||
{ | ||
value: "add a role", | ||
value: "role", | ||
}, | ||
{ | ||
value: "add an employee", | ||
value: "employee", | ||
}, | ||
{ | ||
value: "update an employee role", | ||
} | ||
]; | ||
// define the set of primary options to display to the user while navigating the app in the terminal. | ||
const mainOptions = [ | ||
{ value: "VIEW TABLES"}, | ||
{ value: "ADD SOMETHING NEW"}, | ||
{ value: "UPDATE EXISTING DATA"} | ||
]; | ||
|
||
//define the main prompt function that will run on startup and be referred back to throughout | ||
|
||
function mainPrompt() { | ||
inquirer.prompt( | ||
{ | ||
type:'list', | ||
message: "omg what do you want", | ||
choices: options, | ||
message: "Tell us what your heart desires", | ||
choices: mainOptions, | ||
name: "desire" | ||
}, | ||
).then((answers) => { | ||
let table; | ||
// let val = answers; | ||
switch (answers.desire) { | ||
case "view all departments": | ||
table = 'department'; | ||
break; | ||
case "view all roles": | ||
table = 'role'; | ||
break; | ||
case "view all employees": | ||
table = 'employee'; | ||
break; | ||
} | ||
// console.log(choices[0]); | ||
// const table = 'department'; | ||
connection.query( | ||
`SELECT * FROM ${table}`, function(err,results,fields) { | ||
console.log(`\x1b[35m here is your results \x1b[0m`) | ||
console.table(results); | ||
} | ||
); | ||
if (answers = "HR VIEW") { | ||
inquirer.prompt( | ||
{ | ||
type:'list', | ||
message:'we can sort results 3 ways, what would you like to view?', | ||
choices: options, | ||
name: "viewChoice" | ||
},).then((answers) => { | ||
console.log('\x1b[35m ok here you go \x1b[0m') | ||
console.log(answers.viewChoice) | ||
viewTable(answers.viewChoice); | ||
}) //end .then statement | ||
|
||
} // end if statement | ||
|
||
}); | ||
} //end my start function | ||
mainPrompt(); | ||
|
||
function viewTable(tableChoice) { | ||
switch (tableChoice){ | ||
case "department": | ||
connection.query( | ||
`SELECT * FROM ${tableChoice}`, function(err,results,fields) { | ||
console.log('\x1b[35m here is list of our departments \x1b[0m') | ||
console.table(results); }); | ||
break; | ||
case "role": | ||
connection.query( | ||
`select role.title as job_title, department.name as department from role join department on role.department_id = department.id`, function(err, results, fields) { | ||
console.log("\x1b[35m here is list of the company's positions and their respective departments \x1b[0m") | ||
console.table(results); | ||
}); | ||
break; | ||
}//.then(() => {console.log('looks great huh?') | ||
//mainPrompt(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters