Total Complexity | 2 |
Total Lines | 16 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { Inject } from '@nestjs/common'; |
||
6 | |||
7 | @CommandHandler(RemoveProductCommand) |
||
8 | export class RemoveProductCommandHandler { |
||
9 | constructor( |
||
10 | @Inject('IProductRepository') |
||
11 | private readonly productRepository: IProductRepository, |
||
12 | ) {} |
||
13 | |||
14 | public async execute({ id }: RemoveProductCommand): Promise<void> { |
||
15 | const product = await this.productRepository.findOneById(id); |
||
16 | |||
17 | if (!product) { |
||
18 | throw new ProductNotFoundException(); |
||
19 | } |
||
20 | |||
21 | await this.productRepository.remove(product); |
||
22 | } |
||
24 |