Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 26 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 { IUserRepository } from 'src/Domain/User/Repository/IUserRepository'; |
||
5 | import { School } from '../../School/School.entity'; |
||
6 | import { UserRole } from '../User.entity'; |
||
7 | |||
8 | export class CanUserAccessToSchool { |
||
9 | constructor( |
||
10 | @Inject('IUserRepository') |
||
11 | private readonly userRepository: IUserRepository, |
||
12 | @Inject('ISchoolUserRepository') |
||
13 | private readonly schoolUserRepository: ISchoolUserRepository |
||
14 | ) {} |
||
15 | |||
16 | public async isSatisfiedBy(school: School, userId: string): Promise<boolean> { |
||
17 | const user = await this.userRepository.findOneById(userId); |
||
18 | if (!user) { |
||
19 | return false; |
||
20 | } |
||
21 | |||
22 | return user.getRole() === UserRole.PHOTOGRAPHER || |
||
23 | (await this.schoolUserRepository.findOneByUserAndSchool(user, school)) instanceof SchoolUser; |
||
24 | } |
||
25 | } |
||
26 |