Passed
Push — master ( 647f1d...d78cb9 )
by Mathieu
02:20 queued 24s
created

RemoveProductCommandHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 15
dl 0
loc 16
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A execute 0 9 2
1
import { Inject } from '@nestjs/common';
2
import { CommandHandler } from '@nestjs/cqrs';
3
import { ProductNotFoundException } from 'src/Domain/Product/Exception/ProductNotFoundException';
4
import { IProductRepository } from 'src/Domain/Product/Repository/IProductRepository';
5
import { RemoveProductCommand } from './RemoveProductCommand';
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
  }
23
}
24