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

54 lines
1.7 KiB
TypeScript
Raw Normal View History

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> {
let events;
if (req.query?.project) {
events = await this.eventService.getEventsForProject(
req.query.project,
);
} else {
events = await this.eventService.getEvents();
}
eventDiffer.addDiffs(events);
res.json({ version, events });
}
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;
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' });
}
}
}
module.exports = EventController;