dto对象

This commit is contained in:
Jeremy Yin 2019-06-17 23:25:43 +08:00
parent aea8856148
commit 34ea934195
2 changed files with 7 additions and 3 deletions

3
src/posts/post.dto.ts Normal file
View File

@ -0,0 +1,3 @@
export class CreatePostDto {
readonly title: string
}

View File

@ -1,4 +1,5 @@
import { Controller, Get, Post, Req, Query, Headers, Param, Body } from '@nestjs/common';
import { CreatePostDto } from './post.dto';
@Controller('posts')
export class PostsController {
@ -21,8 +22,8 @@ export class PostsController {
}
@Post()
store(@Body() body) {
console.log(body)
return body
store(@Body() post: CreatePostDto) {
console.log(post)
return post
}
}