Skip to content

Commit

Permalink
adds master prompt function and showTable function
Browse files Browse the repository at this point in the history
  • Loading branch information
JDR8888 committed Mar 16, 2023
1 parent 2708208 commit 6cd56bf
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 52 deletions.
2 changes: 2 additions & 0 deletions dbFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


96 changes: 55 additions & 41 deletions index.js
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();
};
22 changes: 11 additions & 11 deletions notes.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
view all departments,
view all roles,
mysql> source query.sql
+-----------------------------------+-----------------+
| job_title | department |
+-----------------------------------+-----------------+
| swiper | logistics |
| assistant to the regional manager | sales |
| pencil pusher | human resources |
+----------------------------------
- view all departments,
- view all roles,
view all employees,
add a department,
add a role,
Expand All @@ -25,4 +17,12 @@ View employees by department.

Delete departments, roles, and employees.

View the total utilized budget of a department—in other words, the combined salaries of all employees in that department.
View the total utilized budget of a department—in other words, the combined salaries of all employees in that department.

+-----------------------------------+-----------------+
| job_title | department |
+-----------------------------------+-----------------+
| swiper | logistics |
| assistant to the regional manager | sales |
| pencil pusher | human resources |
+----------------------------------

0 comments on commit 6cd56bf

Please sign in to comment.