This repository was archived by the owner on Dec 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
68 lines (61 loc) · 1.71 KB
/
api.js
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
const router = require('express').Router();
const productsData = require('./productsData.js')
const barsData = require('./barsData.js')
router.get('/bars', function(req, res) {
let result = [];
if (req.query.location) {
result = [{
id: 5,
name: "Cloisters Bar",
lat: 55.9432624,
long: -3.2107057,
image_url: "https://lh5.googleusercontent.com/-XpI50JzpRug/UFs9Fz493zI/AAAAAAAAQKQ/Pud2p6KwLzYcrNNs2mSwb_B3PCvh7YyLQCJkC/w160-h184-p-k-no/"
},{
id: 8,
name: "Blue Blazer",
lat: 55.945942,
long: -3.2053387,
image_url: "https://lh3.googleusercontent.com/--PVUZuR2JG8/VzHHbMYaTvI/AAAAAAAAADE/6FTK5x3Kwo8TQeDKo8QY4Q_eSVWA2Yh9wCJkC/w160-h184-p-k-no/"
},{
id: 4,
name: "Bennets Bar",
lat: 55.941731,
long: -3.2120178,
image_url: "https://lh5.googleusercontent.com/-IqgRrXlxDLI/VX7cfy1LFII/AAAAAAAAAA0/iqL3kWyra6UkXC0DP9eNmMD4QumhzCTLACJkC/w160-h184-p-k-no/"
}];
} else if (req.query.search) {
const pattern = req.query.search
result = barsData.filter((item) => {
return item.name.toLowerCase().startsWith(pattern.toLowerCase())
})
}
res.json({
data: result
});
});
router.get('/bars/:barId/products', function(req, res) {
res.json({
data: productsData
});
})
router.get('/bars/:barId/history', function(req, res) {
res.json({
data: [{
id: 1120921,
bar_id: 1,
ordered_at: 1486936031375,
total: 27.7
},{
id: 2323198,
bar_id: 1,
ordered_at: 1486938134586,
total: 25.3
}]
});
})
router.post('/bars/:barId/history', function(req, res) {
const data = req.body
data.id = Math.round(Math.random() * 1000)
res.json(data)
})
module.exports = router