1
- import { Body , Controller , Patch , Post , UseGuards } from '@nestjs/common' ;
1
+ import { Body , Controller , Post , Req , UseGuards } from '@nestjs/common' ;
2
2
import { UserReportService } from './user-report.service' ;
3
3
import { PostUserReportSwagger } from './user-report.swagger' ;
4
4
import { ApiBearerAuth , ApiTags } from '@nestjs/swagger' ;
5
5
import { CreateUserReportDto } from './dto/user-report.dto' ;
6
6
import { BaseResponse } from 'src/common/response/dto' ;
7
+ import { AuthGuard } from 'src/auth/guards/jwt.auth.guard' ;
8
+ import { Request } from 'express' ;
9
+ import { UnauthorizedException } from 'src/common/exception/service.exception' ;
7
10
8
11
@ApiBearerAuth ( 'Authorization' )
9
12
@Controller ( 'user-report' )
13
+ @UseGuards ( AuthGuard )
10
14
@ApiTags ( '[서비스] 유저 신고' )
11
15
export class UserReportController {
12
16
constructor ( private readonly userReportService : UserReportService ) { }
@@ -15,12 +19,27 @@ export class UserReportController {
15
19
@PostUserReportSwagger ( '유저 신고하기 API' )
16
20
async postUserReport (
17
21
@Body ( ) createUserReportDto : CreateUserReportDto ,
22
+ @Req ( ) req : Request
18
23
) : Promise < BaseResponse < null > > {
19
- const fromUserId = 1 ; // 나중에 인증 로직 완성되면 유저 인증하자
24
+ const fromUserId = req . user [ 'id' ] ;
25
+ //console.log("fromUserId is ~~~~~~~~~~~~~", fromUserId);
26
+ //console.log("createUserReportDto.fromUserId is ~~~~~~~~~~~~~", createUserReportDto.fromUserId);
27
+
28
+ // jwt 유저와 신고할 유저가 다른 경우
29
+ if ( fromUserId != createUserReportDto . fromUserId ) {
30
+ throw UnauthorizedException ( '신고 권한이 없습니다.' ) ;
31
+ }
32
+
20
33
createUserReportDto . fromUserId = fromUserId ;
21
34
22
35
await this . userReportService . createReport ( createUserReportDto ) ;
23
36
24
37
return new BaseResponse < null > ( true , 'USER_REPORTED_SUCCESS' , null ) ;
25
38
}
26
- }
39
+ }
40
+
41
+ /*
42
+ TODO
43
+ - userReport 중복 생성
44
+ - jwt 인증 받은 사람이 아니더라도 신고가 됨 -> 인가
45
+ */
0 commit comments