Total Complexity | 3 |
Complexity/F | 3 |
Lines of Code | 50 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {Inject} from '@nestjs/common'; |
||
2 | import {QueryHandler} from '@nestjs/cqrs'; |
||
3 | import {GetMonthlyEventsQuery} from './GetMonthlyEventsQuery'; |
||
4 | import {IEventRepository} from 'src/Domain/FairCalendar/Repository/IEventRepository'; |
||
5 | import {EventView} from '../View/EventView'; |
||
6 | import {IDateUtils} from 'src/Application/IDateUtils'; |
||
7 | import {EventType} from 'src/Domain/FairCalendar/Event.entity'; |
||
8 | |||
9 | @QueryHandler(GetMonthlyEventsQuery) |
||
10 | export class GetMonthlyEventsQueryHandler { |
||
11 | constructor( |
||
12 | @Inject('IEventRepository') |
||
13 | private readonly eventRepository: IEventRepository, |
||
14 | @Inject('IDateUtils') |
||
15 | private readonly dateUtils: IDateUtils |
||
16 | ) {} |
||
17 | |||
18 | public async execute(query: GetMonthlyEventsQuery): Promise<EventView[]> { |
||
19 | const {date, userId} = query; |
||
20 | const eventViews: EventView[] = []; |
||
21 | const events = await this.eventRepository.findMonthlyEvents( |
||
22 | this.dateUtils.format(date, 'y-MM-dd'), |
||
23 | userId |
||
24 | ); |
||
25 | |||
26 | for (const event of events) { |
||
27 | const project = event.getProject(); |
||
28 | const task = event.getTask(); |
||
29 | |||
30 | let title = event.getType(); |
||
31 | if (EventType.MISSION && project && task) { |
||
32 | title = `[${task.getName()}] ${project.getName()}`; |
||
33 | } |
||
34 | |||
35 | eventViews.push( |
||
36 | new EventView( |
||
37 | event.getId(), |
||
38 | title, |
||
39 | event.getType(), |
||
40 | event.getTime() / 100, |
||
41 | event.getDate(), |
||
42 | event.getSummary() |
||
43 | ) |
||
44 | ); |
||
45 | } |
||
46 | |||
47 | return eventViews; |
||
48 | } |
||
49 | } |
||
50 |