import { Controller , Get , Post , Patch , Query , Delete , Body , Param , Headers , } from '@nestjs/common' ; import { ApiResponse , ApiTags , ApiQuery , ApiBearerAuth , ApiBody , ApiParam , } from '@nestjs/swagger' ; import { HelloService } from './hello.service' ; import { Hello , UserRole } from './classes/hello' ; @ ApiBearerAuth ( ) @ ApiTags ( 'hello' ) @ Controller ( '/hello' ) export class HelloController { constructor ( private readonly helloService ) { } @ Get ( ) @ ApiQuery ( { name : 'name' , required : false } ) @ ApiQuery ( { name : 'role' , enum : UserRole } ) @ ApiResponse ( { status : 200 , description : 'get ...' , type : Hello , } ) fetch ( @ Query ( ) { id } , @ Headers ( 'token' ) token ) { console . log ( token ) ; return this . helloService . fetch ( id ) ; } @ Post ( ) @ ApiBody ( { description : '填写更新内容' } ) save ( @ Body ( ) { message } ) { return this . helloService . save ( message ) ; } @ Patch ( ':id' ) @ ApiParam ( { name : 'id' } ) @ ApiBody ( { description : '请输入message' } ) update ( @ Param ( ) { id } , @ Body ( ) { message } ) { return this . helloService . update ( id , message ) ; } @ Delete ( ) remove ( @ Query ( ) { id } ) { return this . helloService . remove ( id ) ; } }