| Total Complexity | 4 |
| Complexity/F | 4 |
| Lines of Code | 37 |
| 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 { ProjectView } from 'src/Application/Project/View/ProjectView'; |
||
| 8 | import { TaskView } from 'src/Application/Task/View/TaskView'; |
||
| 9 | |||
| 10 | @QueryHandler(GetEventByIdQuery) |
||
| 11 | export class GetEventByIdQueryHandler { |
||
| 12 | constructor( |
||
| 13 | @Inject('IEventRepository') |
||
| 14 | private readonly eventRepository: IEventRepository |
||
| 15 | ) {} |
||
| 16 | |||
| 17 | public async execute(query: GetEventByIdQuery): Promise<EventView> { |
||
| 18 | const event = await this.eventRepository.findOneById(query.id); |
||
| 19 | if (!event) { |
||
| 20 | throw new EventNotFoundException(); |
||
| 21 | } |
||
| 22 | |||
| 23 | const project = event.getProject(); |
||
| 24 | const task = event.getTask(); |
||
| 25 | |||
| 26 | return new EventView( |
||
| 27 | event.getId(), |
||
| 28 | event.getType(), |
||
| 29 | event.getTime(), |
||
| 30 | event.getDate(), |
||
| 31 | event.getSummary(), |
||
| 32 | project ? new ProjectView(project.getId(), project.getName()) : null, |
||
| 33 | task ? new TaskView(task.getId(), task.getName()) : null |
||
| 34 | ); |
||
| 35 | } |
||
| 36 | } |
||
| 37 |