1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00
unleash.unleash/src/lib/routes/admin-api/event.ts

58 lines
1.8 KiB
TypeScript
Raw Normal View History

import { handleErrors } from './util';
import { IUnleashConfig } from '../../types/option';
import { IUnleashServices } from '../../types/services';
import EventService from '../../services/event-service';
import { ADMIN } from '../../types/permissions';
const Controller = require('../controller');
const eventDiffer = require('../../event-differ');
const version = 1;
2014-10-24 15:32:33 +02:00
export default class EventController extends Controller {
private eventService: EventService;
constructor(
config: IUnleashConfig,
{ eventService }: Pick<IUnleashServices, 'eventService'>,
) {
super(config);
this.eventService = eventService;
this.get('/', this.getEvents, ADMIN);
this.get('/:name', this.getEventsForToggle);
}
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
async getEvents(req, res): Promise<void> {
try {
const events = await this.eventService.getEvents();
eventDiffer.addDiffs(events);
res.json({ version, events });
} catch (e) {
handleErrors(res, this.logger, e);
}
}
2014-11-14 07:13:08 +01:00
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
async getEventsForToggle(req, res): Promise<void> {
2016-12-05 17:58:29 +01:00
const toggleName = req.params.name;
try {
const events = await this.eventService.getEventsForToggle(
toggleName,
);
if (events) {
eventDiffer.addDiffs(events);
res.json({ toggleName, events });
} else {
res.status(404).json({ error: 'Could not find events' });
}
} catch (e) {
handleErrors(res, this.logger, e);
}
}
}
module.exports = EventController;