Passed
Pull Request — master (#188)
by Mathieu
02:03
created

server/src/Application/Task/Query/GetTasksQueryHandler.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 26
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 2
mnd 1
bc 1
fnc 1
bpm 1
cpm 2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A GetTasksQueryHandler.execute 0 10 2
1
import {Inject} from '@nestjs/common';
2
import {QueryHandler} from '@nestjs/cqrs';
3
import {GetTasksQuery} from './GetTasksQuery';
4
import {ITaskRepository} from 'src/Domain/Task/Repository/ITaskRepository';
5
import {TaskView} from '../View/TaskView';
6
import {Pagination} from 'src/Application/Common/Pagination';
7
8
@QueryHandler(GetTasksQuery)
9
export class GetTasksQueryHandler {
10
  constructor(
11
    @Inject('ITaskRepository')
12
    private readonly taskRepository: ITaskRepository
13
  ) {}
14
15
  public async execute(query: GetTasksQuery): Promise<Pagination<TaskView>> {
16
    const taskViews: TaskView[] = [];
17
    const [tasks, total] = await this.taskRepository.findTasks(query.page);
18
19
    for (const task of tasks) {
20
      taskViews.push(new TaskView(task.getId(), task.getName()));
21
    }
22
23
    return new Pagination<TaskView>(taskViews, total);
24
  }
25
}
26