给post dto 的 title 加上字符串验证
This commit is contained in:
parent
fee353b81f
commit
83943ece43
|
@ -1,3 +1,6 @@
|
|||
import { IsString } from 'class-validator'
|
||||
|
||||
export class CreatePostDto {
|
||||
@IsString()
|
||||
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 { 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue