api/src/Application/Calendar/Command/AbstractEventCommandHandler.ts   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 32
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
A AbstractEventCommandHandler.getUser 0 8 2
A AbstractEventCommandHandler.getSchool 0 8 2
1
import { ISchoolRepository } from 'src/Domain/School/Repository/ISchoolRepository';
2
import { SchoolNotFoundException } from 'src/Domain/School/Exception/SchoolNotFoundException';
3
import { IUserRepository } from 'src/Domain/User/Repository/IUserRepository';
4
import { UserNotFoundException } from 'src/Domain/User/Exception/UserNotFoundException';
5
import { User } from 'src/Domain/User/User.entity';
6
import { School } from 'src/Domain/School/School.entity';
7
8
export abstract class AbstractEventCommandHandler {
9
  constructor(
10
    private readonly schoolRepository: ISchoolRepository,
11
    private readonly userRepository: IUserRepository
12
  ) {}
13
14
  protected async getUser(userId: string): Promise<User> {
15
    const user = await this.userRepository.findOneById(userId);
16
    if (!user) {
17
      throw new UserNotFoundException();
18
    }
19
20
    return user;
21
  }
22
23
  protected async getSchool(schoolId: string): Promise<School> {
24
    const school = await this.schoolRepository.findOneById(schoolId);
25
    if (!school) {
26
      throw new SchoolNotFoundException();
27
    }
28
29
    return school;
30
  }
31
}
32