1
- import { Controller , Get , Patch } from '@nestjs/common' ;
1
+ import {
2
+ Body ,
3
+ Controller ,
4
+ Get ,
5
+ Param ,
6
+ Patch ,
7
+ Req ,
8
+ UseGuards ,
9
+ } from '@nestjs/common' ;
2
10
import { UserService } from './user.service' ;
3
11
import { ApiBearerAuth , ApiTags } from '@nestjs/swagger' ;
4
12
import {
@@ -7,6 +15,15 @@ import {
7
15
PatchUserTermsSwagger ,
8
16
SignOutSwagger ,
9
17
} from './user.swagger' ;
18
+ import { AuthGuard } from 'src/auth/guards/jwt.auth.guard' ;
19
+ import { PatchUserRequest } from './dto/patch-user.request' ;
20
+ import { BaseResponse } from 'src/common/response/dto' ;
21
+ import { Request } from 'express' ;
22
+ import {
23
+ DataNotFoundException ,
24
+ UnauthorizedException ,
25
+ } from 'src/common/exception/service.exception' ;
26
+ import { PatchUserResponse } from './dto/patch-user.response' ;
10
27
11
28
@ApiBearerAuth ( 'Authorization' )
12
29
@Controller ( 'user' )
@@ -26,10 +43,28 @@ export class UserController {
26
43
// return this.userService.getHello();
27
44
}
28
45
29
- @Patch ( )
46
+ @Patch ( ':userId' )
47
+ @UseGuards ( AuthGuard )
30
48
@PatchUserSwagger ( '유저 정보 수정 API' )
31
- patchUser ( ) {
32
- // return this.userService.getHello();
49
+ async patchUser (
50
+ @Req ( ) req : Request ,
51
+ @Param ( 'userId' ) userId : number ,
52
+ @Body ( ) body : PatchUserRequest ,
53
+ ) : Promise < BaseResponse < PatchUserResponse > > {
54
+ if ( ! ( await this . userService . getUserById ( userId ) ) )
55
+ throw DataNotFoundException ( '유저가 존재하지 않습니다.' ) ;
56
+ if ( req . user . id !== Number ( userId ) ) {
57
+ throw UnauthorizedException ( '권한이 없습니다.' ) ;
58
+ }
59
+
60
+ const updatedUser = await this . userService . PatchUser ( userId , body ) ;
61
+
62
+ return new BaseResponse < PatchUserResponse > ( true , '유저 정보 수정 성공' , {
63
+ userId : updatedUser . id ,
64
+ nickname : updatedUser . nickname ,
65
+ profilePictureUrl : updatedUser . profilePictureUrl ,
66
+ bio : updatedUser . bio ,
67
+ } ) ;
33
68
}
34
69
35
70
@Patch ( )
0 commit comments