-
Notifications
You must be signed in to change notification settings - Fork 4
/
create-user.event.controller.ts
33 lines (29 loc) · 1.13 KB
/
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
31
32
33
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 { Roles } from 'src/interface-adapters/enum/roles.enum';
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,
universityID: payload.universityID,
fullName: {
firstName: payload.firstName,
lastName: payload.lastName,
},
password: payload.password,
role: Roles.librarian,
});
const id = await this.createUser.createUser(command);
return new IdResponse(id.value);
}
}