refactor: 调整user/me和user/password获取user的方法
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Body, Controller, Get, Put, Request, UseGuards } from '@nestjs/common';
|
||||
import { UserService } from './user.service';
|
||||
import { UpdateUserPasswordDto } from './dto/update-user-password.dto';
|
||||
import { AuthService } from 'src/auth/auth.service';
|
||||
import { AuthGuard } from 'src/auth/guards/auth.guard';
|
||||
import { AuthUser, CurrentUser } from 'src/auth/decorator/current-user.decorator';
|
||||
|
||||
@Controller('user')
|
||||
export class UserController {
|
||||
@@ -12,14 +12,13 @@ export class UserController {
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Get('me')
|
||||
async getMe(@Request() req) {
|
||||
const { user } = req;
|
||||
async getMe(@CurrentUser() user: AuthUser) {
|
||||
return this.userService.findById(user.userId);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Put('password')
|
||||
async update(@Request() req, @Body() dto: UpdateUserPasswordDto) {
|
||||
return this.userService.setPassword(req.user.userId, dto.password);
|
||||
async update(@CurrentUser() user: AuthUser, @Body() dto: UpdateUserPasswordDto) {
|
||||
return this.userService.setPassword(user.userId, dto.password);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user