87 lines
2.3 KiB
TypeScript
87 lines
2.3 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Body,
|
|
UseGuards,
|
|
UseInterceptors,
|
|
UploadedFile,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
import { UserService } from './user.service';
|
|
import { JwtAuthGuard } from '@/common/guards/jwt-auth.guard';
|
|
import { CurrentUser } from '@/common/decorators/current-user.decorator';
|
|
import {
|
|
UpdateProfileDto,
|
|
ChangePasswordDto,
|
|
VerifyIdentityDto,
|
|
} from './dto/user.dto';
|
|
|
|
@ApiTags('用户')
|
|
@Controller('app')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
export class UserUserController {
|
|
constructor(private readonly userService: UserService) {}
|
|
|
|
@Get('profile')
|
|
@ApiOperation({ summary: '获取个人信息' })
|
|
async getProfile(@CurrentUser('sub') userId: number) {
|
|
return this.userService.findById(userId);
|
|
}
|
|
|
|
@Post('profile')
|
|
@ApiOperation({ summary: '更新个人信息' })
|
|
async updateProfile(
|
|
@CurrentUser('sub') userId: number,
|
|
@Body() dto: UpdateProfileDto,
|
|
) {
|
|
return this.userService.updateProfile(userId, dto);
|
|
}
|
|
|
|
@Post('avatar')
|
|
@ApiOperation({ summary: '上传头像' })
|
|
@UseInterceptors(FileInterceptor('file'))
|
|
async uploadAvatar(
|
|
@CurrentUser('sub') userId: number,
|
|
@UploadedFile() file: Express.Multer.File,
|
|
) {
|
|
return this.userService.uploadAvatar(userId, file);
|
|
}
|
|
|
|
@Put('profile')
|
|
@ApiOperation({ summary: '更新个人信息(旧接口,保留兼容)' })
|
|
async updateProfilePut(
|
|
@CurrentUser('sub') userId: number,
|
|
@Body() dto: UpdateProfileDto,
|
|
) {
|
|
return this.userService.updateProfile(userId, dto);
|
|
}
|
|
|
|
@Put('password')
|
|
@ApiOperation({ summary: '修改密码' })
|
|
async changePassword(
|
|
@CurrentUser('sub') userId: number,
|
|
@Body() dto: ChangePasswordDto,
|
|
) {
|
|
return this.userService.changePassword(userId, dto);
|
|
}
|
|
|
|
@Post('verify')
|
|
@ApiOperation({ summary: '实名认证' })
|
|
async verifyIdentity(
|
|
@CurrentUser('sub') userId: number,
|
|
@Body() dto: VerifyIdentityDto,
|
|
) {
|
|
return this.userService.verifyIdentity(userId, dto);
|
|
}
|
|
|
|
@Get('verify/status')
|
|
@ApiOperation({ summary: '获取实名认证状态' })
|
|
async getVerifyStatus(@CurrentUser('sub') userId: number) {
|
|
return this.userService.getVerifyStatus(userId);
|
|
}
|
|
}
|