1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| import { Controller, Get, Post, Body, Patch, Param, Delete, HttpStatus, HttpException } from '@nestjs/common'; import { UserService } from './user.service'; import { CreateUserDto } from './dto/create-user.dto'; import { UpdateUserDto } from './dto/update-user.dto'; import { ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
@Controller('user') @ApiTags('用户') export class UserController { constructor(private readonly userService: UserService) { }
@Post() @ApiOperation({ summary: '创建用户' }) create(@Body() createUserDto: CreateUserDto) { return this.userService.create(createUserDto); }
@Get() @ApiOperation({ summary: '查询所有用户' }) findAll() { const a = process.env.SALT return this.userService.findAll(); }
@Get(':id') @ApiOperation({ summary: '根据id查询用户' }) findOne(@Param('id') id: string) { const user = this.userService.findOne(+id) if (!user) { throw new HttpException('用户不存在', HttpStatus.NOT_FOUND) } else { return user } }
@Patch(':id') @ApiOperation({ summary: '根据id更新用户' }) update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) { return this.userService.update(+id, updateUserDto); }
@Delete(':id') @ApiOperation({ summary: '根据id删除用户' }) remove(@Param('id') id: string) { return this.userService.remove(+id); } }
|