forked from Sairyss/domain-driven-hexagon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-user.http.controller.ts
44 lines (40 loc) · 1.3 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
import { Body, Controller, HttpStatus, Inject, Post } from '@nestjs/common';
import { IdResponse } from 'src/interface-adapters/dtos/id.response.dto';
import { routes } from '@config/app.routes';
import { createUserSymbol } from '@modules/user/user.providers';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
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)
@ApiOperation({ summary: 'Create a user' })
@ApiResponse({
status: HttpStatus.OK,
type: IdResponse,
})
@ApiResponse({
status: HttpStatus.CONFLICT,
description: 'User already exists',
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
})
async create(@Body() body: CreateUserRequest): Promise<IdResponse> {
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 IdResponse(id.value);
}
}