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 850c948..592ecd3 100644 --- a/routes/index.js +++ b/routes/index.js @@ -6,23 +6,21 @@ 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', + title: 'Shopping Cart', products: products } ); }); -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 : {}); var product = products.filter(function(item) { - return item.id == productId; + return item.id === productId; }); cart.add(product[0], productId); req.session.cart = 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 @@ -38,13 +36,13 @@ 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 }); }); -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 : {});