Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 33 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
2 | import { Inject } from '@nestjs/common'; |
||
3 | import { GetSchoolUsersQuery } from './GetSchoolUsersQuery'; |
||
4 | import { ISchoolUserRepository } from 'src/Domain/School/Repository/ISchoolUserRepository'; |
||
5 | import { SchoolUserView } from 'src/Application/School/View/SchoolUserView'; |
||
6 | |||
7 | @QueryHandler(GetSchoolUsersQuery) |
||
8 | export class GetSchoolUsersQueryHandler { |
||
9 | constructor( |
||
10 | @Inject('ISchoolUserRepository') |
||
11 | private readonly schoolUserRepository: ISchoolUserRepository |
||
12 | ) {} |
||
13 | |||
14 | public async execute(query: GetSchoolUsersQuery): Promise<SchoolUserView[]> { |
||
15 | const schoolUserViews: SchoolUserView[] = []; |
||
16 | const schoolUsers = await this.schoolUserRepository.findUsersBySchool(query.schoolId); |
||
17 | |||
18 | for (const schoolUser of schoolUsers) { |
||
19 | const user = schoolUser.getUser(); |
||
20 | |||
21 | schoolUserViews.push( |
||
22 | new SchoolUserView( |
||
23 | schoolUser.getId(), |
||
24 | user.getEmail(), |
||
25 | 'schoolUser' |
||
26 | ) |
||
27 | ); |
||
28 | } |
||
29 | |||
30 | return schoolUserViews; |
||
31 | } |
||
32 | } |
||
33 |