From 83943ece4359ef5c8b0f9e94bd8779ba5b1bce45 Mon Sep 17 00:00:00 2001 From: Jeremy Yin Date: Wed, 19 Jun 2019 21:22:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99post=20dto=20=E7=9A=84=20title=20?= =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E5=AD=97=E7=AC=A6=E4=B8=B2=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/posts/post.dto.ts | 3 +++ src/modules/posts/posts.controller.ts | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/posts/post.dto.ts b/src/modules/posts/post.dto.ts index 4783ca3..632f55a 100644 --- a/src/modules/posts/post.dto.ts +++ b/src/modules/posts/post.dto.ts @@ -1,3 +1,6 @@ +import { IsString } from 'class-validator' + export class CreatePostDto { + @IsString() readonly title: string } \ No newline at end of file diff --git a/src/modules/posts/posts.controller.ts b/src/modules/posts/posts.controller.ts index 5352b0c..056aae9 100644 --- a/src/modules/posts/posts.controller.ts +++ b/src/modules/posts/posts.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Post, Req, Query, Headers, Param, Body, HttpException, HttpStatus, ForbiddenException, UseFilters } from '@nestjs/common'; +import { Controller, Get, Post, Req, Query, Headers, Param, Body, HttpException, HttpStatus, ForbiddenException, UseFilters, UsePipes, ValidationPipe } from '@nestjs/common'; import { CreatePostDto } from './post.dto'; import { DemoService } from './providers/demo/demo.service' import { DemoFilter } from '../../core/filters/demo.filter' @@ -24,9 +24,10 @@ export class PostsController { @Post() // @UseFilters(DemoFilter) + @UsePipes(ValidationPipe) store(@Body() post: CreatePostDto) { // throw new HttpException('没有权限!', HttpStatus.FORBIDDEN) - throw new ForbiddenException('没有权限!') - // this.demoService.create(post); + // throw new ForbiddenException('没有权限!') + this.demoService.create(post); } }