-
Notifications
You must be signed in to change notification settings - Fork 83
/
todo-completed.integration-handler.ts
49 lines (42 loc) · 1.55 KB
/
todo-completed.integration-handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Infra, Application, ok, Either } from '@bitloops/bl-boilerplate-core';
import { TodoCompletedIntegrationEvent } from '@src/lib/bounded-contexts/todo/todo/contracts/integration-events/todo-completed.integration-event';
import { IncrementTodosCommand } from '../../../commands/Increment-todos.command';
import { StreamingCommandBusToken } from '../../../constants';
import { Inject } from '@nestjs/common';
import { Traceable } from '@bitloops/bl-boilerplate-infra-telemetry';
export class TodoCompletedIntegrationEventHandler
implements Application.IHandleIntegrationEvent
{
constructor(
@Inject(StreamingCommandBusToken)
private commandBus: Infra.CommandBus.IStreamCommandBus,
) {}
get event() {
return TodoCompletedIntegrationEvent;
}
get boundedContext() {
return TodoCompletedIntegrationEvent.boundedContextId;
}
get version() {
return TodoCompletedIntegrationEvent.versions[0]; // here output will be 'v1'
}
@Traceable({
operation: '[Marketing] TodoCompletedIntegrationEventHandler',
serviceName: 'Marketing',
metrics: {
name: '[Marketing] TodoCompletedIntegrationEventHandler',
category: 'integrationEventHandler',
},
})
public async handle(
event: TodoCompletedIntegrationEvent,
): Promise<Either<void, never>> {
const { payload } = event;
const command = new IncrementTodosCommand({ id: payload.userId });
await this.commandBus.publish(command);
console.log(
`[TodoCompletedIntegrationEvent]: Successfully sent IncrementTodosCommand`,
);
return ok();
}
}