api/src/Domain/User/Specification/IsUserAlreadyAddedToSchool.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 23
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A IsUserAlreadyAddedToSchool.isSatisfiedBy 0 8 2
1
import { Inject } from '@nestjs/common';
2
import { ISchoolUserRepository } from 'src/Domain/School/Repository/ISchoolUserRepository';
3
import { SchoolUser } from 'src/Domain/School/SchoolUser.entity';
4
import { School } from '../../School/School.entity';
5
import { User, UserRole } from '../User.entity';
6
7
export class IsUserAlreadyAddedToSchool {
8
  constructor(
9
    @Inject('ISchoolUserRepository')
10
    private readonly schoolUserRepository: ISchoolUserRepository
11
  ) {}
12
13
  public async isSatisfiedBy(school: School, user: User): Promise<boolean> {
14
    if (user.getRole() === UserRole.PHOTOGRAPHER) {
15
      return true;
16
    }
17
18
    return (
19
      (await this.schoolUserRepository.findOneByUserAndSchool(user, school)) instanceof SchoolUser
20
    );
21
  }
22
}
23