Passed
Push — master ( 74fcec...dc846b )
by
unknown
02:16
created

server/src/Application/Contact/Command/DeleteContactCommandHandler.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 26
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 22
mnd 1
bc 1
fnc 1
dl 0
loc 26
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A DeleteContactCommandHandler.execute 0 11 2
1
import { Inject } from '@nestjs/common';
2
import { CommandHandler } from '@nestjs/cqrs';
3
import { ContactNotFoundException } from 'src/Domain/Contact/Exception/ContactNotFoundException';
4
import { IContactRepository } from 'src/Domain/Contact/Repository/IContactRepository';
5
import { DeleteContactCommand } from './DeleteContactCommand';
6
7
@CommandHandler(DeleteContactCommand)
8
export class DeleteContactCommandHandler {
9
  constructor(
10
    @Inject('IContactRepository')
11
    private readonly contactRepository: IContactRepository
12
  ) {}
13
14
  public async execute(command: DeleteContactCommand): Promise<void> {
15
    const { id } = command;
16
17
    const contact = await this.contactRepository.findOneById(id);
18
19
    if (!contact) {
20
      throw new ContactNotFoundException();
21
    }
22
23
    await this.contactRepository.remove(contact);
24
  }
25
}
26