2016-06-18 21:53:18 +02:00
|
|
|
'use strict';
|
2016-10-26 10:43:11 +02:00
|
|
|
|
2018-11-30 10:11:36 +01:00
|
|
|
const Controller = require('../controller');
|
2017-06-28 10:20:22 +02:00
|
|
|
|
|
|
|
const eventDiffer = require('../../event-differ');
|
2016-09-05 16:50:52 +02:00
|
|
|
const version = 1;
|
2014-10-24 15:32:33 +02:00
|
|
|
|
2018-11-30 10:11:36 +01:00
|
|
|
class EventController extends Controller {
|
2018-12-19 14:50:01 +01:00
|
|
|
constructor(config) {
|
|
|
|
super(config);
|
|
|
|
this.eventStore = config.stores.eventStore;
|
2018-11-30 10:11:36 +01:00
|
|
|
this.get('/', this.getEvents);
|
|
|
|
this.get('/:name', this.getEventsForToggle);
|
|
|
|
}
|
2016-05-01 22:53:09 +02:00
|
|
|
|
2018-11-30 10:11:36 +01:00
|
|
|
async getEvents(req, res) {
|
|
|
|
const events = await this.eventStore.getEvents();
|
|
|
|
eventDiffer.addDiffs(events);
|
|
|
|
res.json({ version, events });
|
|
|
|
}
|
2014-11-14 07:13:08 +01:00
|
|
|
|
2018-11-30 10:11:36 +01:00
|
|
|
async getEventsForToggle(req, res) {
|
2016-12-05 17:58:29 +01:00
|
|
|
const toggleName = req.params.name;
|
2018-11-30 10:11:36 +01:00
|
|
|
const events = await this.eventStore.getEventsFilterByName(toggleName);
|
|
|
|
|
|
|
|
if (events) {
|
|
|
|
eventDiffer.addDiffs(events);
|
|
|
|
res.json({ toggleName, events });
|
|
|
|
} else {
|
|
|
|
res.status(404).json({ error: 'Could not find events' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2018-11-30 10:11:36 +01:00
|
|
|
module.exports = EventController;
|