Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 23 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |