From 34ea9341959ee7075003cb06c2736052c256139a Mon Sep 17 00:00:00 2001 From: Jeremy Yin Date: Mon, 17 Jun 2019 23:25:43 +0800 Subject: [PATCH] =?UTF-8?q?dto=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/posts/post.dto.ts | 3 +++ src/posts/posts.controller.ts | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 src/posts/post.dto.ts diff --git a/src/posts/post.dto.ts b/src/posts/post.dto.ts new file mode 100644 index 0000000..4783ca3 --- /dev/null +++ b/src/posts/post.dto.ts @@ -0,0 +1,3 @@ +export class CreatePostDto { + readonly title: string +} \ No newline at end of file diff --git a/src/posts/posts.controller.ts b/src/posts/posts.controller.ts index 3576975..e51b874 100644 --- a/src/posts/posts.controller.ts +++ b/src/posts/posts.controller.ts @@ -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 } }