1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/lib/routes/admin-api/event.js

36 lines
965 B
JavaScript

'use strict';
const Controller = require('../controller');
const eventDiffer = require('../../event-differ');
const version = 1;
class EventController extends Controller {
constructor(config) {
super(config);
this.eventStore = config.stores.eventStore;
this.get('/', this.getEvents);
this.get('/:name', this.getEventsForToggle);
}
async getEvents(req, res) {
const events = await this.eventStore.getEvents();
eventDiffer.addDiffs(events);
res.json({ version, events });
}
async getEventsForToggle(req, res) {
const toggleName = req.params.name;
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' });
}
}
}
module.exports = EventController;