import { Controller , Get , Post , Patch , Query , Delete , Body , Param , Headers , UseFilters , HttpException , HttpStatus , ParseIntPipe , } from '@nestjs/common' ; import { ApiTags , ApiBearerAuth , ApiBody , ApiParam , } from '@nestjs/swagger' ; import { ExceptionService } from './exception.service' ; import { HttpExceptionFilter } from '../../common/filters/http-exception.filter' ; @ ApiBearerAuth ( ) @ ApiTags ( 'exception' ) @ Controller ( '/exception' ) export class ExceptionController { constructor ( private readonly exceptionService ) { } @ Get ( ) fetch ( @ Query ( ) { id } , @ Headers ( 'token' ) token ) { if ( ! id ) { throw new HttpException ( { status : HttpStatus . BAD_REQUEST , message : '请求参数id 必传' , error : 'id is required' } , HttpStatus . BAD_REQUEST ) ; } return this . exceptionService . fetch ( id ) ; } @ Post ( ) @ ApiBody ( { description : '填写更新内容' } ) save ( @ Body ( ) { message , id } ) { return this . exceptionService . save ( message ) ; } @ Patch ( ':id' ) @ ApiParam ( { name : 'id' } ) @ ApiBody ( { description : '请输入message' } ) update ( @ Param ( 'id' , new ParseIntPipe ( ) ) id , @ Body ( ) { message } ) { console . log ( typeof id ) ; return this . exceptionService . update ( id , message ) ; } @ Delete ( ) remove ( @ Query ( ) { id } ) { return this . exceptionService . remove ( id ) ; } }