| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 28 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { Inject } from '@nestjs/common'; |
||
| 2 | import { CommandHandler } from '@nestjs/cqrs'; |
||
| 3 | import { ShootingNotFoundException } from 'src/Domain/School/Exception/ShootingNotFoundException'; |
||
| 4 | import { IShootingRepository } from 'src/Domain/School/Repository/IShootingRepository'; |
||
| 5 | import { UpdateShootingCommand } from './UpdateShootingCommand'; |
||
| 6 | |||
| 7 | @CommandHandler(UpdateShootingCommand) |
||
| 8 | export class UpdateShootingCommandHandler { |
||
| 9 | constructor( |
||
| 10 | @Inject('IShootingRepository') |
||
| 11 | private readonly shootingRepository: IShootingRepository, |
||
| 12 | ) { } |
||
| 13 | |||
| 14 | public async execute(command: UpdateShootingCommand): Promise<string> { |
||
| 15 | const { name, closingDate, shootingDate, id } = command; |
||
| 16 | |||
| 17 | const shooting = await this.shootingRepository.findOneById(id); |
||
| 18 | if (!shooting) { |
||
| 19 | throw new ShootingNotFoundException(); |
||
| 20 | } |
||
| 21 | |||
| 22 | shooting.update(name, shootingDate, closingDate); |
||
| 23 | await this.shootingRepository.save(shooting); |
||
| 24 | |||
| 25 | return shooting.getId(); |
||
| 26 | } |
||
| 27 | } |
||
| 28 |