import { Controller , Get , Post , Body , Patch , Param , Delete , ParseIntPipe , UseGuards , UseInterceptors , ClassSerializerInterceptor , } from '@nestjs/common' ; import { UserService } from './user.service' ; import { CreateUserDto } from './dto/create-user.dto' ; import { UpdateUserDto } from './dto/update-user.dto' ; import { ApiBearerAuth , ApiBody , ApiResponse , ApiTags } from '@nestjs/swagger' ; import { Roles } from '../roles/roles.decorator' ; import { Role } from '../roles/roles.interface' ; import { RolesGuard } from '../auth/guards/roles.guard' ; import { User } from './entities/user.entity' ; @ ApiTags ( '用户详情' ) @ ApiBearerAuth ( ) @ Controller ( 'user' ) export class UserController { constructor ( private readonly userService ) { } @ ApiBody ( { type : CreateUserDto } ) @ ApiResponse ( { type : User } ) @ UseInterceptors ( ClassSerializerInterceptor ) @ Post ( ) async create ( @ Body ( ) createUserDto ) { return this . userService . create ( createUserDto ) ; } @ ApiResponse ( { type : [ User ] } ) @ Roles ( Role . Admin ) @ UseGuards ( RolesGuard ) @ UseInterceptors ( ClassSerializerInterceptor ) @ Get ( ) async findAll ( ) { return this . userService . findAll ( ) ; } @ ApiResponse ( { type : User } ) @ UseInterceptors ( ClassSerializerInterceptor ) @ Get ( ':id' ) async findOne ( @ Param ( 'id' , ParseIntPipe ) id ) { return this . userService . findOne ( + id ) ; } @ ApiBody ( { type : UpdateUserDto } ) @ ApiResponse ( { type : User } ) @ Patch ( ':id' ) async update ( @ Param ( 'id' , ParseIntPipe ) id , @ Body ( ) updateUserDto ) { return this . userService . update ( + id , updateUserDto ) ; } @ Delete ( ':id' ) async remove ( @ Param ( 'id' , ParseIntPipe ) id ) { return this . userService . remove ( + id ) ; } }