Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 24 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { Inject } from '@nestjs/common'; |
||
2 | import { CommandHandler } from '@nestjs/cqrs'; |
||
3 | import { SchoolUserNotFoundException } from 'src/Domain/School/Exception/SchoolUserNotFoundException'; |
||
4 | import { ISchoolUserRepository } from 'src/Domain/School/Repository/ISchoolUserRepository'; |
||
5 | import { RemoveSchoolUserCommand } from './RemoveSchoolUserCommand'; |
||
6 | |||
7 | @CommandHandler(RemoveSchoolUserCommand) |
||
8 | export class RemoveSchoolUserCommandHandler { |
||
9 | constructor( |
||
10 | @Inject('ISchoolUserRepository') |
||
11 | private readonly schoolUserRepository: ISchoolUserRepository, |
||
12 | ) {} |
||
13 | |||
14 | public async execute({ id }: RemoveSchoolUserCommand): Promise<void> { |
||
15 | const schoolUser = await this.schoolUserRepository.findOneById(id); |
||
16 | |||
17 | if (!schoolUser) { |
||
18 | throw new SchoolUserNotFoundException(); |
||
19 | } |
||
20 | |||
21 | await this.schoolUserRepository.remove(schoolUser); |
||
22 | } |
||
23 | } |
||
24 |