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 {GetEventsOverview} from 'src/Domain/FairCalendar/GetEventsOverview'; |
8
|
|
|
import {MonthlyEventsView} from '../View/MonthlyEventsView'; |
9
|
|
|
import {ProjectView} from 'src/Application/Project/View/ProjectView'; |
10
|
|
|
import {TaskView} from 'src/Application/Task/View/TaskView'; |
11
|
|
|
|
12
|
|
|
@QueryHandler(GetMonthlyEventsQuery) |
13
|
|
|
export class GetMonthlyEventsQueryHandler { |
14
|
|
|
constructor( |
15
|
|
|
@Inject('IEventRepository') |
16
|
|
|
private readonly eventRepository: IEventRepository, |
17
|
|
|
@Inject('IDateUtils') |
18
|
|
|
private readonly dateUtils: IDateUtils, |
19
|
|
|
private readonly getEventsOverview: GetEventsOverview |
20
|
|
|
) {} |
21
|
|
|
|
22
|
|
|
public async execute( |
23
|
|
|
query: GetMonthlyEventsQuery |
24
|
|
|
): Promise<MonthlyEventsView> { |
25
|
|
|
const {date, userId} = query; |
26
|
|
|
const eventViews: EventView[] = []; |
27
|
|
|
const events = await this.eventRepository.findMonthlyEvents( |
28
|
|
|
this.dateUtils.format(date, 'y-MM-dd'), |
29
|
|
|
userId |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
const overview = this.getEventsOverview.index(events); |
33
|
|
|
|
34
|
|
|
for (const event of events) { |
35
|
|
|
const project = event.getProject(); |
36
|
|
|
const task = event.getTask(); |
37
|
|
|
|
38
|
|
|
eventViews.push( |
39
|
|
|
new EventView( |
40
|
|
|
event.getId(), |
41
|
|
|
event.getType(), |
42
|
|
|
event.getTime() / 100, |
43
|
|
|
event.getDate(), |
44
|
|
|
event.getSummary(), |
45
|
|
|
project ? new ProjectView(project.getId(), project.getName()) : null, |
46
|
|
|
task ? new TaskView(task.getId(), task.getName()) : null |
47
|
|
|
) |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return new MonthlyEventsView(eventViews, overview); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|