2021-04-22 10:07:10 +02:00
|
|
|
import { IUnleashConfig } from '../types/option';
|
|
|
|
import { IUnleashStores } from '../types/stores';
|
|
|
|
import { Logger } from '../logger';
|
2021-08-12 15:04:37 +02:00
|
|
|
import { IEventStore } from '../types/stores/event-store';
|
2022-09-02 08:35:31 +02:00
|
|
|
import { IEventList } from '../types/events';
|
2022-08-09 16:14:50 +02:00
|
|
|
import { SearchEventsSchema } from '../openapi/spec/search-events-schema';
|
2021-04-22 10:07:10 +02:00
|
|
|
|
|
|
|
export default class EventService {
|
|
|
|
private logger: Logger;
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
private eventStore: IEventStore;
|
2021-04-22 10:07:10 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
{ eventStore }: Pick<IUnleashStores, 'eventStore'>,
|
|
|
|
{ getLogger }: Pick<IUnleashConfig, 'getLogger'>,
|
|
|
|
) {
|
|
|
|
this.logger = getLogger('services/event-service.ts');
|
|
|
|
this.eventStore = eventStore;
|
|
|
|
}
|
|
|
|
|
2022-09-02 08:35:31 +02:00
|
|
|
async getEvents(): Promise<IEventList> {
|
|
|
|
let totalEvents = await this.eventStore.count();
|
|
|
|
let events = await this.eventStore.getEvents();
|
|
|
|
return {
|
|
|
|
events,
|
|
|
|
totalEvents,
|
|
|
|
};
|
2021-04-22 10:07:10 +02:00
|
|
|
}
|
|
|
|
|
2022-09-02 08:35:31 +02:00
|
|
|
async searchEvents(search: SearchEventsSchema): Promise<IEventList> {
|
|
|
|
let totalEvents = await this.eventStore.filteredCount(search);
|
|
|
|
let events = await this.eventStore.searchEvents(search);
|
|
|
|
return {
|
|
|
|
events,
|
|
|
|
totalEvents,
|
|
|
|
};
|
2021-09-20 12:13:38 +02:00
|
|
|
}
|
2021-04-22 10:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = EventService;
|