Skip to content

new title!! #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ app.use(session({
secret: 'secret',
resave: false,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

beep beep marks !!

Copy link
Collaborator Author

@RMacfarlane RMacfarlane Dec 9, 2019

Choose a reason for hiding this comment

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

oh marks???

saveUninitialized: true
}))
}));
app.use(express.static(path.join(__dirname, 'public')));

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

helllo

// res.locals is an object passed to hbs engine
Expand All @@ -39,14 +39,14 @@ app.use(function(req, res, next) {
app.use('/', index);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
app.use(function(_req, _res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handler
app.use(function(err, req, res, next) {
app.use(function(err, req, res, _next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
Expand Down
2 changes: 2 additions & 0 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ a {
.dropdown-menu .cart {
min-width: 250px;
padding: 15px 25px 0;
margin: 0;
}

.dropdown-menu .cart .row > div {
padding: 0 0 10px 0;
margin: 0;
}

.dropdown-menu .cart .totalPrice{
Expand Down
12 changes: 5 additions & 7 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -17,20 +15,20 @@ 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 : {});
var product = products.filter(function(item) {
return item.id == productId;
return item.id === productId;
});
cart.add(product[0], productId);
req.session.cart = cart;
res.redirect('/');
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
Expand All @@ -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 : {});

Expand Down