| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Delete, |
| 5 | Get, |
| 6 | Param, |
| 7 | Put, |
| 8 | Query, |
| 9 | } from '@nestjs/common'; |
| 10 | import { UserService } from './user.service'; |
| 11 | import { QueryUserListDto, UpdateUserStatusDto } from './dto/user-admin.dto'; |
| 12 | import { AppHttpException } from '../filters/http-exception.filter'; |
| 13 | import { ErrHttpBack } from '../filters/http-exception.back-code'; |
| 14 | import { Manager } from '../auth/manager.guard'; |
| 15 | |
| 16 | @Manager() |
| 17 | @Controller('admin/user') |
| 18 | export class UserAdminController { |
| 19 | constructor(private readonly userService: UserService) {} |
| 20 | |
| 21 | // @ApiOperation({ summary: '获取用户列表' }) |
| 22 | @Get('list') |
| 23 | async getUserList(@Query() query: QueryUserListDto) { |
| 24 | return this.userService.getUserList(query); |
| 25 | } |
| 26 | |
| 27 | // @ApiOperation({ summary: '获取用户详情' }) |
| 28 | @Get('info/:id') |
| 29 | async getUserDetail(@Param('id') id: string) { |
| 30 | const userInfo = await this.userService.getUserInfoById(id); |
| 31 | if (!userInfo) throw new AppHttpException(ErrHttpBack.err_user_no_had); |
| 32 | return userInfo; |
| 33 | } |
| 34 | |
| 35 | // @ApiOperation({ summary: '更新用户状态' }) |
| 36 | @Put(':id/status') |
| 37 | async updateUserStatus( |
| 38 | @Param('id') id: string, |
| 39 | @Body() body: UpdateUserStatusDto, |
| 40 | ) { |
| 41 | const userInfo = await this.userService.getUserInfoById(id); |
| 42 | if (!userInfo) throw new AppHttpException(ErrHttpBack.err_user_no_had); |
| 43 | |
| 44 | return this.userService.updateUserStatus(id, body.status); |
| 45 | } |
| 46 | |
| 47 | // 删除用户 |
| 48 | @Delete(':id') |
| 49 | async deleteUser(@Param('id') id: string) { |
| 50 | const userInfo = await this.userService.getUserInfoById(id); |
| 51 | if (!userInfo) throw new AppHttpException(ErrHttpBack.err_user_no_had); |
| 52 | |
| 53 | return this.userService.deleteUser(userInfo); |
| 54 | } |
| 55 | |
| 56 | // 用户总数 |
| 57 | @Get('count') |
| 58 | async getUserCount() { |
| 59 | return this.userService.getUserCount(); |
| 60 | } |
| 61 | } |
| 62 |