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
Ivar Conradi Østhus d01c9d2dac
fix: use airbnb lint rules directly (#583)
This drops usage of finn-eslint rules as they are no
longer maintained.
2020-04-14 22:29:11 +02:00

37 lines
966 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;