1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/src/lib/services/event-service.ts
Christopher Kolstad ae19cae8a9
feat: add count to event list (#2036)
* feat: add count to event list
2022-09-02 08:35:31 +02:00

41 lines
1.2 KiB
TypeScript

import { IUnleashConfig } from '../types/option';
import { IUnleashStores } from '../types/stores';
import { Logger } from '../logger';
import { IEventStore } from '../types/stores/event-store';
import { IEventList } from '../types/events';
import { SearchEventsSchema } from '../openapi/spec/search-events-schema';
export default class EventService {
private logger: Logger;
private eventStore: IEventStore;
constructor(
{ eventStore }: Pick<IUnleashStores, 'eventStore'>,
{ getLogger }: Pick<IUnleashConfig, 'getLogger'>,
) {
this.logger = getLogger('services/event-service.ts');
this.eventStore = eventStore;
}
async getEvents(): Promise<IEventList> {
let totalEvents = await this.eventStore.count();
let events = await this.eventStore.getEvents();
return {
events,
totalEvents,
};
}
async searchEvents(search: SearchEventsSchema): Promise<IEventList> {
let totalEvents = await this.eventStore.filteredCount(search);
let events = await this.eventStore.searchEvents(search);
return {
events,
totalEvents,
};
}
}
module.exports = EventService;