1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/lib/routes/admin-api/event.js

36 lines
953 B
JavaScript

'use strict';
const Controller = require('../controller');
const eventDiffer = require('../../event-differ');
const version = 1;
class EventController extends Controller {
constructor({ eventStore }) {
super();
this.eventStore = 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;