forked from Sairyss/domain-driven-hexagon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-user.event.controller.ts
30 lines (26 loc) · 1016 Bytes
/
create-user.event.controller.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
import { createUserSymbol } from '@modules/user/user.providers';
import { Inject } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
import { IdResponse } from 'src/interface-adapters/dtos/id.response.dto';
import { CreateUserCommand } from './create-user.command';
import { CreateUserRequest } from './create-user.request.dto';
import { CreateUserService } from './create-user.service';
export class CreateUserEventController {
constructor(
@Inject(createUserSymbol)
private readonly createUser: CreateUserService,
) {}
@MessagePattern('user.create') // <- Subscribe to microservice event
async create(payload: CreateUserRequest): Promise<IdResponse> {
const command = new CreateUserCommand({
email: payload.email,
address: {
country: payload.country,
postalCode: payload.postalCode,
street: payload.street,
},
});
const id = await this.createUser.createUser(command);
return new IdResponse(id.value);
}
}