Passed
Push — master ( f58cd4...647f1d )
by Mathieu
01:52
created

RemoveDiscountCommandHandler.execute   A

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
1
import { Inject } from '@nestjs/common';
2
import { CommandHandler } from '@nestjs/cqrs';
3
import { DiscountNotFoundException } from 'src/Domain/School/Exception/DiscountNotFoundException';
4
import { IDiscountRepository } from 'src/Domain/School/Repository/IDiscountRepository';
5
import { RemoveDiscountCommand } from './RemoveDiscountCommand';
6
7
@CommandHandler(RemoveDiscountCommand)
8
export class RemoveDiscountCommandHandler {
9
  constructor(
10
    @Inject('IDiscountRepository')
11
    private readonly discountRepository: IDiscountRepository,
12
  ) {}
13
14
  public async execute({ id }: RemoveDiscountCommand): Promise<void> {
15
    const discount = await this.discountRepository.findOneById(id);
16
17
    if (!discount) {
18
      throw new DiscountNotFoundException();
19
    }
20
21
    await this.discountRepository.remove(discount);
22
  }
23
}
24