Passed
Pull Request — master (#216)
by
unknown
02:07
created

server/src/Application/Contact/Query/GetContactsQueryHandler.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 40
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 40
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 GetContactsQueryHandler.execute 0 24 2
1
import { Inject } from '@nestjs/common';
2
import { QueryHandler } from '@nestjs/cqrs';
3
import { GetContactsQuery } from './GetContactsQuery';
4
import { ContactView } from '../View/ContactView';
5
import { IContactRepository } from 'src/Domain/Contact/Repository/IContactRepository';
6
import { Pagination } from 'src/Application/Common/Pagination';
7
8
@QueryHandler(GetContactsQuery)
9
export class GetContactsQueryHandler {
10
  constructor(
11
    @Inject('IContactRepository')
12
    private readonly contactRepository: IContactRepository
13
  ) {}
14
15
  public async execute(
16
    query: GetContactsQuery
17
  ): Promise<Pagination<ContactView>> {
18
    const contactsView: ContactView[] = [];
19
    const [contacts, total] = await this.contactRepository.findContacts(
20
      query.page
21
    );
22
23
    for (const contact of contacts) {
24
      contactsView.push(
25
        new ContactView(
26
          contact.getId(),
27
          contact.getFirstName(),
28
          contact.getLastName(),
29
          contact.getCompany(),
30
          contact.getEmail(),
31
          contact.getPhoneNumber(),
32
          contact.getNotes()
33
        )
34
      );
35
    }
36
37
    return new Pagination<ContactView>(contactsView, total);
38
  }
39
}
40