Skip to content

Commit d0f759e

Browse files
committed
Refactor inquirer code to get department list from departments table
1 parent 6b13604 commit d0f759e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

bamazonManager.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ const handleAddInventory = (id, quantity) => {
117117

118118
// Handle menu option 4
119119
const handleAddNewProduct = () => {
120+
let departmentList = [];
121+
// Get list of departments from departments table
122+
connection.query("SELECT department_name FROM departments", function (err, res) {
123+
if (err) throw (err);
124+
res.forEach((department) => {
125+
departmentList.push(department.department_name)
126+
})
127+
});
128+
120129
inquirer
121130
.prompt([
122131
{
@@ -126,7 +135,7 @@ const handleAddNewProduct = () => {
126135
},
127136
{
128137
type: "list",
129-
choices: ["Electronics", "Clothing", "Households", "Grocery"],
138+
choices: departmentList,
130139
name: "productDepartment",
131140
message: "Enter Product Department:"
132141
},
@@ -171,3 +180,5 @@ const handleMenuExit = () => {
171180
console.log('\nExited Manager Menu\n'.bold.underline.red)
172181
connection.end();
173182
};
183+
184+

bamazonSupervisor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const handleSupervisorOption = (input) => {
4747
};
4848

4949
const displayProductSales = () => {
50-
connection.query("SELECT departments.department_id, departments.department_name, departments.over_head_costs, SUM(products.product_sales) AS product_sales, (departments.over_head_costs - SUM(products.product_sales)) AS total_profit FROM products RIGHT JOIN departments ON products.department_name = departments.department_name GROUP BY products.department_name, departments.department_id ORDER BY departments.department_id",
50+
connection.query("SELECT departments.department_id, departments.department_name, departments.over_head_costs, SUM(products.product_sales) AS product_sales, (SUM(products.product_sales) - departments.over_head_costs) AS total_profit FROM products RIGHT JOIN departments ON products.department_name = departments.department_name GROUP BY products.department_name, departments.department_id ORDER BY departments.department_id",
5151
function (err, res) {
5252
if (err) throw (err);
5353
console.log(`\nList of bamazon departments:\n`.bold.underline.cyan)

0 commit comments

Comments
 (0)