forked from Sairyss/domain-driven-hexagon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-user.http.controller.ts
32 lines (27 loc) · 1000 Bytes
/
create-user.http.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
import { Body, Controller, Inject, Post } from '@nestjs/common';
import { IdResponseDTO } from 'src/interface-adapters/dtos/id.response.dto';
import { routes } from '@config/app.routes';
import { createUserSymbol } from '@modules/user/user.providers';
import { CreateUserCommand } from './create-user.command';
import { CreateUserService } from './create-user.service';
import { CreateUserRequest } from './create-user.request.dto';
@Controller()
export class CreateUserHttpController {
constructor(
@Inject(createUserSymbol)
private readonly createUser: CreateUserService,
) {}
@Post(routes.user.root)
async create(@Body() body: CreateUserRequest): Promise<IdResponseDTO> {
const command = new CreateUserCommand({
email: body.email,
address: {
country: body.country,
postalCode: body.postalCode,
street: body.street,
},
});
const id = await this.createUser.createUser(command);
return new IdResponseDTO(id.value);
}
}