api/src/Application/School/Query/User/GetSchoolUsersQueryHandler.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 33
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A GetSchoolUsersQueryHandler.execute 0 18 2
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