Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
steveww committed Jan 25, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 0dc55b8 commit 689a88c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cart/server.js
Original file line number Diff line number Diff line change
@@ -99,8 +99,8 @@ app.get('/add/:id/:sku/:qty', (req, res) => {
var list = mergeList(cart.items, item, qty);
cart.items = list;
cart.total = calcTotal(cart.items);
// work out tax @ 20%
cart.tax = (cart.total - (cart.total / 1.2));
// work out tax
cart.tax = calcTax(cart.total);

// save the new cart
saveCart(req.params.id, cart);
@@ -149,8 +149,8 @@ app.get('/update/:id/:sku/:qty', (req, res) => {
cart.items[idx].subtotal = cart.items[idx].price * qty;
}
cart.total = calcTotal(cart.items);
// work out tax @ 20%
cart.tax = (cart.total - (cart.total / 1.2)).toFixed(2);
// work out tax
cart.tax = calcTax(cart.total);
saveCart(req.params.id, cart);
res.json(cart);
}
@@ -186,8 +186,8 @@ app.post('/shipping/:id', (req, res) => {
};
cart.items.push(item);
cart.total = calcTotal(cart.items);
// work out tax @ 20%
cart.tax = (cart.total - (cart.total / 1.2));
// work out tax
cart.tax = calcTax(cart.total);

// save the updated cart
saveCart(req.params.id, cart);
@@ -229,6 +229,11 @@ function calcTotal(list) {
return total;
}

function calcTax(total) {
// tax @ 20%
return (total - (total / 1.2));
}

function getProduct(sku) {
return new Promise((resolve, reject) => {
request('http://catalogue:8080/product/' + sku, (err, res, body) => {

0 comments on commit 689a88c

Please sign in to comment.