Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions menuStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
function menu(){

const menu = {

burgers: {
1: {
id: 1,
name: "Regular Burger",
price: 8.0,
quantity: 1,
description: "Bun, Signature Patty, Tomato, Lettuce, Pickle, Signature Sauce",
extras: []
},
2: {
id: 2,
name: "Irregular Burger",
price: 9.5,
quantity: 1,
description: "Bun, Signature Patty, Peppers, Cheese, Tomato, Lettuce, Pickle, Signature Sauce",
extras: []
},
3: {
id: 3,
name: "SuperBurger",
price: 10.5,
quantity: 1,
description: "Bun, Signature Patty, Fried Plantain, Avocado, Peanut Butter",
extras: []
},
4: {
id: 4,
name: "IncrediBurger",
price: 12.0,
quantity: 1,
description: "Bun, Signature Patty, Hash Brown, Cheese, Avocado Tomato, Lettuce, Pickle, Signature Sauce",
extras: []
}
},

fries: {
5:{
id: 5,
name: "Regular Fries",
price: 2.5,
description: "Hand cut, triple-cooked fries",
quantity: 1
},
6:{
id: 6,
name: "Spicy Fries",
price: 3.5,
description: "Hand cut, triple-cooked fries with house seasoning and garlic mayo",
quantity: 1
},
7:{
id: 7,
name: "Cheese Fries",
price: 4.5,
description: "Hand cut, triple-cooked Halloumi slices",
quantity: 1
},
},

extras: {
8:{
id: 8,
name: "Chipotle Mayo",
price: 1,
quantity: 1
},
9:{
id: 9,
name: "Extra Avocado",
price: 1.5,
quantity: 1
},
10:{
id: 10,
name: "Extra Cheese",
price: 1.5,
quantity: 1
},
11:{
id: 11,
name: "Hash Brown",
price: 2,
quantity: 1
},
12:{
id: 12,
name: "Double Patty",
price: 3,
quantity: 1
},
}
};

const menuMethods ={
retrieveMenu(){
return menu;
}
}

return menuMethods;
}

module.exports = menu;
79 changes: 79 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"test": "jest",
"dev": "webpack --mode development",
"build": "webpack --mode production"
"build": "webpack --mode production",
"start": "nodemon server.js"
},
"author": "",
"license": "ISC",
Expand All @@ -18,11 +19,13 @@
},
"dependencies": {
"body-parser": "^1.18.3",
"classnames": "^2.2.6",
"express": "^4.16.3",
"hbs": "^4.0.1",
"jest": "^22.3.0",
"react": "^16.2.0",
"react-dom": "^16.2.0"
"react-dom": "^16.2.0",
"react-router": "^4.3.1"
},
"devDependencies": {
"babel-jest": "^22.4.1",
Expand Down
61 changes: 44 additions & 17 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
const express = require('express');
const bodyParser = require('body-parser');
const express = require("express");
const bodyParser = require("body-parser");
const menu = require('./menuStorage');
const app = express();

app.use(bodyParser.json());
app.use('/static', express.static('static'));
app.set('view engine', 'hbs');

const menu = {
1: {
id: 1,
name: "Strawberry cheesecake",
price: 6
}
};

app.get('/', function(req, res){
res.render('index');
app.use("/static", express.static("static"));
app.set("view engine", "hbs");

const menuMethods = menu();

function orders() {
let order = {};

const orderMethods = {
addOrder(incomingOrder) {
let nextId;
const orderIds = Object.keys(order);
orderIds.length === 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ternary returns a value so it would be better to use

const nextId = orderIds.length === 0 ? 1 : Math.max(...orderIds) + 1;

? (nextId = 1)
: (nextId = Math.max(...orderIds) + 1);
order[nextId] = {
id: nextId,
orderItems: incomingOrder.orderItems,
orderTotal: incomingOrder.orderTotal
};
return order[nextId];
}
};
return orderMethods;
}

app.get("/", function(req, res) {
res.render("index");
});

app.get("/api/menu", function(req, res) {
const currentMenu = menuMethods.retrieveMenu();
res.json(currentMenu);
});

app.post("/api/order", (req, res) => {
const orderMethods = orders();
const newOrder = orderMethods.addOrder(req.body);
res.json(newOrder);
});

app.listen(8080, function(){
console.log('Listening on port 8080');
app.listen(8080, function() {
console.log("Listening on port 8080");
});
Loading