forked from eljamaki01/ReactNodeTesting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarts.js
More file actions
73 lines (69 loc) · 1.81 KB
/
carts.js
File metadata and controls
73 lines (69 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var express = require('express');
var router = express.Router();
let activeCarts = [
{
cartID: "777",
cartItems: [
{
title: "Fresh Strawberries",
description: "Assorted sizes, 2 cartons",
cost: 200,
imageUrl: "stawberries.jpg"
},
{
title: "Fresh Blackberries",
description: "Assorted sizes, 2 cartons",
cost: 295,
imageUrl: "blackberries.jpg"
},
{
title: "Delicious Cookies",
description: "Homemade chocolate chip cookies, 1 dozen",
cost: 450,
imageUrl: "cookies.jpg"
},
{
title: "Organic Blueberries",
description: "Fresh picked, 3 cartons",
cost: 350,
imageUrl: "blackberries.jpg"
},
{
title: "Gourmet Cookie Box",
description: "Assorted flavors, premium selection",
cost: 599,
imageUrl: "cookies.jpg"
}
]
},
{
cartID: "888",
cartItems: [
{
title: "Yummy cookies",
description: "Flour and chocolate chips",
cost: 150,
imageUrl: "cookies.jpg"
}
]
}
]
//
// Return shopping cart items for a cart id.
//
// NOTE: for if have a JWT that need to be validated will need that middleware inserted
// router.get('/:id', authHelper.checkAuth, function (req, res, next) {
router.get('/:id', function (req, res, next) {
// TODO: Return a 404 error if the cart ID does not exist!
let cart = activeCarts.find(x => x.cartID === req.params.id)
if (cart === undefined) {
let err = new Error('Cart was not found.');
err.status = 404;
return next(err);
}
res.header("Cache-Control", "no-cache, no-store, must-revalidate");
res.header("Pragma", "no-cache");
res.header("Expires", 0);
res.status(200).json(cart);
});
module.exports = router;