给post dto 的 title 加上字符串验证
This commit is contained in:
		
							parent
							
								
									fee353b81f
								
							
						
					
					
						commit
						83943ece43
					
				|  | @ -1,3 +1,6 @@ | ||||||
|  | import { IsString } from 'class-validator' | ||||||
|  | 
 | ||||||
| export class CreatePostDto { | export class CreatePostDto { | ||||||
|  |    @IsString() | ||||||
|    readonly title: string |    readonly title: string | ||||||
| } | } | ||||||
|  | @ -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 { CreatePostDto } from './post.dto'; | ||||||
| import { DemoService } from './providers/demo/demo.service' | import { DemoService } from './providers/demo/demo.service' | ||||||
| import { DemoFilter } from '../../core/filters/demo.filter' | import { DemoFilter } from '../../core/filters/demo.filter' | ||||||
|  | @ -24,9 +24,10 @@ export class PostsController { | ||||||
| 
 | 
 | ||||||
|     @Post() |     @Post() | ||||||
|     // @UseFilters(DemoFilter)
 |     // @UseFilters(DemoFilter)
 | ||||||
|  |     @UsePipes(ValidationPipe) | ||||||
|     store(@Body() post: CreatePostDto) { |     store(@Body() post: CreatePostDto) { | ||||||
|         // throw new HttpException('没有权限!', HttpStatus.FORBIDDEN)
 |         // throw new HttpException('没有权限!', HttpStatus.FORBIDDEN)
 | ||||||
|         throw new ForbiddenException('没有权限!') |         // throw new ForbiddenException('没有权限!')
 | ||||||
|         // this.demoService.create(post);
 |         this.demoService.create(post); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue