-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.controller.ts
More file actions
33 lines (30 loc) · 1.02 KB
/
Copy pathexample.controller.ts
File metadata and controls
33 lines (30 loc) · 1.02 KB
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 { Body, Controller, Get, Param, Post, Req } from '@nestjs/common'
import { Request } from 'express'
import { WebReqUtil } from 'lyxe/lib/web/WebReqUtil'
import { TAddExampleUserDto } from '../domain/example-dtos'
import { AddExampleUser } from '../domain/AddExampleUser'
import { ExampleUserReadService } from '../domain/ExampleUserReadService'
@Controller('/api/example')
export class ExampleController {
@Get('/hello')
async hello() {
return {
message: 'Hello from LyxeJS!'
}
}
@Post('/')
async createUser(@Body() dto: TAddExampleUserDto, @Req() req: Request) {
const user = await WebReqUtil.createContextService(AddExampleUser, req).runFromDto(dto)
return {
id: user.getId()
}
}
@Get('/name/:name')
async listByNameQuery(@Param('name') name: string, @Req() req: Request) {
const users = await WebReqUtil.createContextService(ExampleUserReadService, req).listByNameQuery(name)
return users.map((user) => ({
id: user.getId(),
name: user.getName()
}))
}
}