From 4adbb6d93ba020ca4bc805ad72fbaf471bfc287c Mon Sep 17 00:00:00 2001 From: Rachel Macfarlane Date: Wed, 20 Jun 2018 11:59:42 -0700 Subject: [PATCH 1/2] Remove unused variables --- routes/index.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/routes/index.js b/routes/index.js index 850c948..cc2d62a 100644 --- a/routes/index.js +++ b/routes/index.js @@ -6,9 +6,7 @@ var fs = require('fs'); var Cart = require('../models/cart'); var products = JSON.parse(fs.readFileSync('./data/products.json', 'utf8')); -router.get('/', function (req, res, next) { - var productId = products && products[0].id; - +router.get('/', function (_req, res, _next) { res.render('index', { title: 'NodeJS Shopping Cart', @@ -17,7 +15,7 @@ router.get('/', function (req, res, next) { ); }); -router.get('/add/:id', function(req, res, next) { +router.get('/add/:id', function(req, res, _next) { var productId = req.params.id; var cart = new Cart(req.session.cart ? req.session.cart : {}); @@ -30,7 +28,7 @@ router.get('/add/:id', function(req, res, next) { inline(); }); -router.get('/cart', function(req, res, next) { +router.get('/cart', function(req, res, _next) { if (!req.session.cart) { return res.render('cart', { products: null @@ -44,7 +42,7 @@ router.get('/cart', function(req, res, next) { }); }); -router.get('/remove/:id', function(req, res, next) { +router.get('/remove/:id', function(req, res, _next) { var productId = req.params.id; var cart = new Cart(req.session.cart ? req.session.cart : {}); From 4c0354f7905d158da2e4718b9ffc1793c13ede8f Mon Sep 17 00:00:00 2001 From: Rachel Macfarlane Date: Fri, 10 Aug 2018 10:26:12 -0700 Subject: [PATCH 2/2] Update route titles --- data/products.json | 2 +- routes/index.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data/products.json b/data/products.json index baeb90d..7eac8d7 100644 --- a/data/products.json +++ b/data/products.json @@ -14,7 +14,7 @@ { "id": 3, "title": "Garlic", - "description": "Garlic are 15 CHF each", + "description": "Garlic is 15 CHF each", "price": 15 }, { diff --git a/routes/index.js b/routes/index.js index cc2d62a..592ecd3 100644 --- a/routes/index.js +++ b/routes/index.js @@ -9,7 +9,7 @@ var products = JSON.parse(fs.readFileSync('./data/products.json', 'utf8')); router.get('/', function (_req, res, _next) { res.render('index', { - title: 'NodeJS Shopping Cart', + title: 'Shopping Cart', products: products } ); @@ -20,7 +20,7 @@ router.get('/add/:id', function(req, res, _next) { var productId = req.params.id; var cart = new Cart(req.session.cart ? req.session.cart : {}); var product = products.filter(function(item) { - return item.id == productId; + return item.id === productId; }); cart.add(product[0], productId); req.session.cart = cart; @@ -36,7 +36,7 @@ router.get('/cart', function(req, res, _next) { } var cart = new Cart(req.session.cart); res.render('cart', { - title: 'NodeJS Shopping Cart', + title: 'Shopping Cart', products: cart.getItems(), totalPrice: cart.totalPrice });