Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 40 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |