Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 40 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
2 | import { Inject } from '@nestjs/common'; |
||
3 | import { GetSchoolsQuery } from './GetSchoolsQuery'; |
||
4 | import { Pagination } from 'src/Application/Common/Pagination'; |
||
5 | import { ISchoolRepository } from 'src/Domain/School/Repository/ISchoolRepository'; |
||
6 | import { SchoolView } from '../View/SchoolView'; |
||
7 | |||
8 | @QueryHandler(GetSchoolsQuery) |
||
9 | export class GetSchoolsQueryHandler { |
||
10 | constructor( |
||
11 | @Inject('ISchoolRepository') |
||
12 | private readonly schoolRepository: ISchoolRepository |
||
13 | ) {} |
||
14 | |||
15 | public async execute( |
||
16 | query: GetSchoolsQuery |
||
17 | ): Promise<Pagination<SchoolView>> { |
||
18 | const { page } = query; |
||
19 | const schoolViews: SchoolView[] = []; |
||
20 | const [ schools, total ] = await this.schoolRepository.findSchools(page); |
||
21 | |||
22 | for (const school of schools) { |
||
23 | schoolViews.push( |
||
24 | new SchoolView( |
||
25 | school.getId(), |
||
26 | school.getName(), |
||
27 | school.getReference(), |
||
28 | school.getAddress(), |
||
29 | school.getCity(), |
||
30 | school.getZipCode(), |
||
31 | school.getStatus(), |
||
32 | school.getType() |
||
33 | ) |
||
34 | ); |
||
35 | } |
||
36 | |||
37 | return new Pagination<SchoolView>(schoolViews, total); |
||
38 | } |
||
39 | } |
||
40 |