-
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.
added queries.js/ added viewAllEmployees() feature to application
- Loading branch information
Showing
5 changed files
with
117 additions
and
11 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
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,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}; |
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,14 @@ | ||
//Array of application functions. | ||
const commandList = [ | ||
'View all employees', | ||
'Test', | ||
'Test', | ||
'Test', | ||
'Test', | ||
'Test', | ||
'Test', | ||
'Test', | ||
'Quit' | ||
]; | ||
|
||
module.exports = {commandList} |
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,8 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const queries = { | ||
viewAllEmployees: fs.readFileSync(path.join(__dirname, '../sql/viewAllEmp.sql')).toString() | ||
} | ||
|
||
module.exports = queries; |
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,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 |