Passed
Push — master ( 3a2d3a...97549a )
by Mathieu
01:48
created

UpdateShootingCommandHandler.execute   A

Complexity

Conditions 2

Size

Total Lines 13
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 13
rs 9.8
c 0
b 0
f 0
cc 2
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