Skip to content

Commit

Permalink
added queries.js/ added viewAllEmployees() feature to application
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach-EE committed Sep 6, 2021
1 parent 2e27695 commit accb5d6
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 11 deletions.
29 changes: 18 additions & 11 deletions employeeManager.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
const connection = require('./src/config/config');
const commands = require('./src/lib/app');



const init = async () => {
console.log(`
╔═══╗─────╔╗──────────────╔═╗╔═╗
║╔══╝─────║║──────────────║║╚╝║║
║╚══╦╗╔╦══╣║╔══╦╗─╔╦══╦══╗║╔╗╔╗╠══╦═╗╔══╦══╦══╦═╗
║╔══╣╚╝║╔╗║║║╔╗║║─║║║═╣║═╣║║║║║║╔╗║╔╗╣╔╗║╔╗║║═╣╔╝
║╚══╣║║║╚╝║╚╣╚╝║╚═╝║║═╣║═╣║║║║║║╔╗║║║║╔╗║╚╝║║═╣║
╚═══╩╩╩╣╔═╩═╩══╩═╗╔╩══╩══╝╚╝╚╝╚╩╝╚╩╝╚╩╝╚╩═╗╠══╩╝
───────║║──────╔═╝║─────────────────────╔═╝║
───────╚╝──────╚══╝─────────────────────╚══╝`);
console.log('\n\n\n');
console.log(`Welcome to the Employee Manager Application , select desired application command from the list items....`)
console.log(`
╔═══╗─────╔╗──────────────╔═╗╔═╗
║╔══╝─────║║──────────────║║╚╝║║
║╚══╦╗╔╦══╣║╔══╦╗─╔╦══╦══╗║╔╗╔╗╠══╦═╗╔══╦══╦══╦═╗
║╔══╣╚╝║╔╗║║║╔╗║║─║║║═╣║═╣║║║║║║╔╗║╔╗╣╔╗║╔╗║║═╣╔╝
║╚══╣║║║╚╝║╚╣╚╝║╚═╝║║═╣║═╣║║║║║║╔╗║║║║╔╗║╚╝║║═╣║
╚═══╩╩╩╣╔═╩═╩══╩═╗╔╩══╩══╝╚╝╚╝╚╩╝╚╩╝╚╩╝╚╩═╗╠══╩╝
───────║║──────╔═╝║─────────────────────╔═╝║
───────╚╝──────╚══╝─────────────────────╚══╝`);
console.log('\n\n\n');
console.log(`Welcome to the Employee Manager Application , select desired application command from the list items....`);

try {
await commands.start();
} catch (err) {
console.log(err);
}
}

connection.connect((err) => {
Expand Down
62 changes: 62 additions & 0 deletions src/lib/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const connection = require('../config/config');
const consoleTable = require('console.table');
const inquirer = require('inquirer');
const commandList = require('./commandList');
const queries = require('./queries');

const util = require("util");
const query = util.promisify(connection.query).bind(connection);

const start = () => {
inquirer
.prompt({
name: 'action',
type: 'rawlist',
message: 'Please make a decision: ',
choices: commandList.commandList
})
.then((answer) => {
if (answer.action === 'Quit'){
console.log('quit');
}else {
switch (answer.action) {
case commandList.commandList[0]:
console.log(commandList.commandList[0]);
viewAllEmployees();
break;

case commandList.commandList[1]:
console.log(commandList.commandList[1]);
break;

case commandList.commandList[2]:
console.log(commandList.commandList[2]);
break;

case commandList.commandList[3]:
console.log(commandList.commandList[3]);
break;
}
}

});


}
// All DB queries for application
const getEmployees = () => {
return query(queries.viewAllEmployees);
}

const viewAllEmployees = async () => {
try {
const rows = await getEmployees();
console.table(rows);
start();
} catch (err) {
console.log(err);
}
}


module.exports ={start};
14 changes: 14 additions & 0 deletions src/lib/commandList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//Array of application functions.
const commandList = [
'View all employees',
'Test',
'Test',
'Test',
'Test',
'Test',
'Test',
'Test',
'Quit'
];

module.exports = {commandList}
8 changes: 8 additions & 0 deletions src/lib/queries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require('path');
const fs = require('fs');

const queries = {
viewAllEmployees: fs.readFileSync(path.join(__dirname, '../sql/viewAllEmp.sql')).toString()
}

module.exports = queries;
15 changes: 15 additions & 0 deletions src/sql/viewAllEmp.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT
emp.id,
emp.firstname,
emp.lastname,
role.title,
dept.name department,
role.salary,
concat(manager.firstname, " ", manager.lastname) manager_name
FROM
((employee emp
LEFT JOIN employee manager ON manager.id = emp.manager_id)
LEFT JOIN role on emp.role_id = role.id
LEFT JOIN department dept ON role.department_id = dept.id)
ORDER BY
emp.firstname

0 comments on commit accb5d6

Please sign in to comment.