-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.js
30 lines (26 loc) · 830 Bytes
/
events.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
const express = require('express');
const router = express.Router();
const event_store = require("../lib/event_store");
router.get('/feed', function(req, res, next) {
res.json({
events: event_store.getEvents().map(toDisplay),
links: [
{rel: "self", link: "http://localhost:3000/events/feed"},
{rel: "previous", link: "http://localhost:3000/events/feed?start=12345"},
]
});
});
router.get('/:event_id', function(req, res, next) {
let event = event_store.find(parseInt(req.params.event_id));
res.json(toDisplay(event));
});
function toDisplay(event) {
return Object.assign({}, event,
{ timestamp: event.timestamp.toISOString(),
links: [
{rel: "self", link: `http://localhost:3000/events/${event.id}`},
{rel: "feed", link: `http://localhost:3000/events/feed`},
]
});
}
module.exports = router;