Total Complexity | 3 |
Complexity/F | 3 |
Lines of Code | 40 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {QueryHandler} from '@nestjs/cqrs'; |
||
2 | import {Inject} from '@nestjs/common'; |
||
3 | import {GetEventByIdQuery} from './GetEventByIdQuery'; |
||
4 | import {IEventRepository} from 'src/Domain/FairCalendar/Repository/IEventRepository'; |
||
5 | import {EventView} from '../View/EventView'; |
||
6 | import {EventNotFoundException} from 'src/Domain/FairCalendar/Exception/EventNotFoundException'; |
||
7 | import {EventType} from 'src/Domain/FairCalendar/Event.entity'; |
||
8 | |||
9 | @QueryHandler(GetEventByIdQuery) |
||
10 | export class GetEventByIdQueryHandler { |
||
11 | constructor( |
||
12 | @Inject('IEventRepository') |
||
13 | private readonly eventRepository: IEventRepository |
||
14 | ) {} |
||
15 | |||
16 | public async execute(query: GetEventByIdQuery): Promise<EventView> { |
||
17 | const event = await this.eventRepository.findOneById(query.id); |
||
18 | if (!event) { |
||
19 | throw new EventNotFoundException(); |
||
20 | } |
||
21 | |||
22 | const project = event.getProject(); |
||
23 | const task = event.getTask(); |
||
24 | |||
25 | let title = event.getType(); |
||
26 | if (EventType.MISSION && project && task) { |
||
27 | title = `[${task.getName()}] ${project.getName()}`; |
||
28 | } |
||
29 | |||
30 | return new EventView( |
||
31 | event.getId(), |
||
32 | title, |
||
33 | event.getType(), |
||
34 | event.getTime() / 100, |
||
35 | event.getDate(), |
||
36 | event.getSummary() |
||
37 | ); |
||
38 | } |
||
39 | } |
||
40 |