Skip to content
Open
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,
saveUninitialized: true
}))
}));
app.use(express.static(path.join(__dirname, 'public')));

// 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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

0px

Copy link
Collaborator

Choose a reason for hiding this comment

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

start my review

Copy link
Collaborator

Choose a reason for hiding this comment

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

third

Copy link
Collaborator

Choose a reason for hiding this comment

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

a

Copy link
Collaborator

Choose a reason for hiding this comment

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

5

Copy link
Collaborator

Choose a reason for hiding this comment

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

6

}

.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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

good work!

Copy link
Collaborator

Choose a reason for hiding this comment

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

bold italics

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

foo

Copy link
Collaborator

Choose a reason for hiding this comment

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

abc

Copy link
Collaborator

Choose a reason for hiding this comment

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

ctrl + enter to submit

Choose a reason for hiding this comment

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

IMAGE ALT TEXT HERE

Copy link

@alexdima alexdima Aug 29, 2018

Choose a reason for hiding this comment

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

IMAGE ALT TEXT HERE

Choose a reason for hiding this comment

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

IMAGE ALT TEXT HERE

Choose a reason for hiding this comment

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

IMAGE ALT TEXT HERE

Choose a reason for hiding this comment

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

IMAGE ALT TEXT HERE

res.render('index',
{
title: 'NodeJS Shopping Cart',
Expand All @@ -17,20 +15,20 @@ router.get('/', function (req, res, next) {
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Blah:
screen shot 2018-08-22 at 4 48 06 pm

});

router.get('/add/:id', function(req, res, next) {
router.get('/add/:id', function(req, res, _next) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

id?


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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

cart?

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why we use get for a remove action.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch.

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe delete?

Copy link
Collaborator

Choose a reason for hiding this comment

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

or post.

var productId = req.params.id;
var cart = new Cart(req.session.cart ? req.session.cart : {});

Expand Down