| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 41 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { Inject } from '@nestjs/common'; |
||
| 2 | import { CommandHandler } from '@nestjs/cqrs'; |
||
| 3 | import { SchoolNotFoundException } from 'src/Domain/School/Exception/SchoolNotFoundException'; |
||
| 4 | import { ISchoolRepository } from 'src/Domain/School/Repository/ISchoolRepository'; |
||
| 5 | import { IShootingRepository } from 'src/Domain/School/Repository/IShootingRepository'; |
||
| 6 | import { Shooting, ShootingStatus } from 'src/Domain/School/Shooting.entity'; |
||
| 7 | import { CreateShootingCommand } from './CreateShootingCommand'; |
||
| 8 | |||
| 9 | @CommandHandler(CreateShootingCommand) |
||
| 10 | export class CreateShootingCommandHandler { |
||
| 11 | constructor( |
||
| 12 | @Inject('ISchoolRepository') |
||
| 13 | private readonly schoolRepository: ISchoolRepository, |
||
| 14 | @Inject('IShootingRepository') |
||
| 15 | private readonly shootingRepository: IShootingRepository, |
||
| 16 | ) {} |
||
| 17 | |||
| 18 | public async execute(command: CreateShootingCommand): Promise<string> { |
||
| 19 | const { name, groupClosingDate, individualClosingDate, schoolId, shootingDate, notice } = command; |
||
| 20 | |||
| 21 | const school = await this.schoolRepository.findOneById(schoolId); |
||
| 22 | if (!school) { |
||
| 23 | throw new SchoolNotFoundException(); |
||
| 24 | } |
||
| 25 | |||
| 26 | const shooting = await this.shootingRepository.save( |
||
| 27 | new Shooting( |
||
| 28 | name, |
||
| 29 | shootingDate, |
||
| 30 | groupClosingDate, |
||
| 31 | individualClosingDate, |
||
| 32 | ShootingStatus.DISABLED, |
||
| 33 | school, |
||
| 34 | notice |
||
| 35 | ) |
||
| 36 | ); |
||
| 37 | |||
| 38 | return shooting.getId(); |
||
| 39 | } |
||
| 40 | } |
||
| 41 |