Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 24 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {Inject} from '@nestjs/common'; |
||
2 | import {QueryHandler} from '@nestjs/cqrs'; |
||
3 | import {ITaskRepository} from 'src/Domain/Task/Repository/ITaskRepository'; |
||
4 | import {TaskView} from '../View/TaskView'; |
||
5 | import {GetTaskByIdQuery} from './GetTaskByIdQuery'; |
||
6 | import {TaskNotFoundException} from 'src/Domain/Task/Exception/TaskNotFoundException'; |
||
7 | |||
8 | @QueryHandler(GetTaskByIdQuery) |
||
9 | export class GetTaskByIdQueryHandler { |
||
10 | constructor( |
||
11 | @Inject('ITaskRepository') |
||
12 | private readonly taskRepository: ITaskRepository |
||
13 | ) {} |
||
14 | |||
15 | public async execute(query: GetTaskByIdQuery): Promise<TaskView> { |
||
16 | const task = await this.taskRepository.findOneById(query.id); |
||
17 | if (!task) { |
||
18 | throw new TaskNotFoundException(); |
||
19 | } |
||
20 | |||
21 | return new TaskView(task.getId(), task.getName()); |
||
22 | } |
||
23 | } |
||
24 |