test/int/transport-eventbus/handlers/try.aggregate-root.command.handler.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 23
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A TryAggregateRootCommandHandler.execute 0 8 1
1
import { CommandHandler, EventPublisher, ICommandHandler } from '@nestjs/cqrs';
2
import { TryAggregateRootCommand } from '../commands/try.aggregate-root.command';
3
import { Inject } from '@nestjs/common';
4
import { TRANSPORT_EVENT_BUS_PUBLISHER } from '../../../../src/constants/transport.event-bus.constants';
5
import { TestModel } from '../model/test.model';
6
7
@CommandHandler(TryAggregateRootCommand)
8
export class TryAggregateRootCommandHandler implements ICommandHandler<TryAggregateRootCommand> {
9
    constructor(
10
        @Inject(TRANSPORT_EVENT_BUS_PUBLISHER) private readonly publisher: EventPublisher
11
    ) {
12
    }
13
14
    async execute(command: TryAggregateRootCommand) {
15
        const {message} = command;
16
        const aggregator = this.publisher.mergeObjectContext(
17
            new TestModel()
18
        );
19
        aggregator.applyEvent(message);
20
        aggregator.commit();
21
    }
22
}
23