Skip to content

Commit 684571c

Browse files
authored
Merge pull request #110 from umc-commit/fix/104-bigint-error
[FIX] BigInt(undefined) 서버 오류 해결
2 parents 76267fe + 2e68d04 commit 684571c

File tree

5 files changed

+108
-25
lines changed

5 files changed

+108
-25
lines changed

src/common/errors/notification.errors.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,26 @@ export class PushTokenAlreadyExistsError extends BaseError {
120120
data
121121
});
122122
}
123+
}
124+
125+
export class NotificationIdRequiredError extends BaseError {
126+
constructor(data = null) {
127+
super({
128+
errorCode: "N012",
129+
reason: "notificationId가 필요합니다",
130+
statusCode: 400,
131+
data
132+
});
133+
}
134+
}
135+
136+
export class TargetUserIdRequiredError extends BaseError {
137+
constructor(data = null) {
138+
super({
139+
errorCode: "N013",
140+
reason: "target_user_id가 필요합니다",
141+
statusCode: 400,
142+
data
143+
});
144+
}
123145
}

src/common/errors/review.errors.js

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,6 @@ export class ReviewContentTooShortError extends BaseError {
3333
}
3434
}
3535

36-
export class ReviewContentTooLongError extends BaseError {
37-
constructor(data = null) {
38-
super({
39-
errorCode: "R011",
40-
reason: "리뷰 내용이 1000자를 초과합니다",
41-
statusCode: 400, // Bad Request
42-
data,
43-
});
44-
}
45-
}
46-
4736
export class RequestNotFoundError extends BaseError {
4837
constructor(data = null) {
4938
super({
@@ -119,4 +108,48 @@ export class ReviewRatingInvalidError extends BaseError {
119108
data,
120109
});
121110
}
111+
}
112+
113+
export class ReviewContentTooLongError extends BaseError {
114+
constructor(data = null) {
115+
super({
116+
errorCode: "R011",
117+
reason: "리뷰 내용이 1000자를 초과합니다",
118+
statusCode: 400, // Bad Request
119+
data,
120+
});
121+
}
122+
}
123+
124+
export class RequestIdRequiredError extends BaseError {
125+
constructor(data = null) {
126+
super({
127+
errorCode: "R012",
128+
reason: "requestId가 필요합니다",
129+
statusCode: 400, // Bad Request
130+
data,
131+
});
132+
}
133+
}
134+
135+
export class ReviewIdRequiredError extends BaseError {
136+
constructor(data = null) {
137+
super({
138+
errorCode: "R013",
139+
reason: "reviewId가 필요합니다",
140+
statusCode: 400, // Bad Request
141+
data,
142+
});
143+
}
144+
}
145+
146+
export class UserIdRequiredError extends BaseError {
147+
constructor(data = null) {
148+
super({
149+
errorCode: "R014",
150+
reason: "userId가 필요합니다",
151+
statusCode: 400, // Bad Request
152+
data,
153+
});
154+
}
122155
}

src/notification/controller/notification.controller.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { StatusCodes } from "http-status-codes";
2-
import notificationService from '../service/notification.service.js';
32
import { stringifyWithBigInt } from "../../bigintJson.js";
43
import {
5-
NotificationListResponseDto,
6-
NotificationReadResponseDto,
4+
NotificationIdRequiredError
5+
} from '../../common/errors/notification.errors.js';
6+
import {
77
NotificationDeleteResponseDto,
8-
NotificationListItemDto
8+
NotificationListResponseDto,
9+
NotificationReadResponseDto
910
} from '../dto/notification.dto.js';
11+
import notificationService from '../service/notification.service.js';
1012

1113
class NotificationController {
1214

@@ -49,6 +51,9 @@ class NotificationController {
4951
async markNotificationAsRead(req, res, next) {
5052
try {
5153
// URL 파라미터에서 알림 ID를 추출하고 BigInt로 변환
54+
if (!req.params.notificationId) {
55+
throw new NotificationIdRequiredError(); // notificationId가 누락된 경우 NotificationIdRequiredError 반환
56+
}
5257
const notificationId = BigInt(req.params.notificationId);
5358

5459
// 현재 로그인한 사용자 ID

src/notification/fcm/controller/push.controller.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { StatusCodes } from "http-status-codes";
22
import { stringifyWithBigInt } from "../../../bigintJson.js";
33
import {
4+
TargetUserIdRequiredError
5+
} from '../../../common/errors/notification.errors.js';
6+
import {
7+
PushSendResponseDto,
48
PushTokenDeleteResponseDto,
59
PushTokenRegisterDto,
610
PushTokenResponseDto,
7-
TestPushRequestDto,
8-
PushSendResponseDto
11+
TestPushRequestDto
912
} from '../dto/push.dto.js';
1013
import pushService from '../service/push.service.js';
1114

@@ -79,6 +82,9 @@ class PushController {
7982
const testPushDto = new TestPushRequestDto(req.body);
8083

8184
// 대상 사용자 ID 추출
85+
if (!testPushDto.target_user_id) {
86+
throw new TargetUserIdRequiredError(); // target_user_id가 누락된 경우 TargetUserIdRequiredError 반환
87+
}
8288
const targetUserId = BigInt(testPushDto.target_user_id);
8389

8490
// 테스트 Push 발송 서비스 호출

src/review/controller/review.controller.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { StatusCodes } from "http-status-codes";
2-
import reviewService from '../service/review.service.js';
32
import { stringifyWithBigInt } from "../../bigintJson.js";
43
import {
4+
RequestIdRequiredError,
5+
ReviewIdRequiredError,
6+
UserIdRequiredError
7+
} from '../../common/errors/review.errors.js';
8+
import {
9+
ImageUploadResponseDto,
510
ReviewCreateDto,
6-
ReviewUpdateDto,
11+
ReviewListResponseDto,
712
ReviewResponseDto,
8-
ImageUploadResponseDto,
9-
ReviewListResponseDto
13+
ReviewUpdateDto
1014
} from '../dto/review.dto.js'; // DTO 클래스 import
15+
import reviewService from '../service/review.service.js';
1116

1217
class ReviewController {
1318

@@ -42,10 +47,13 @@ class ReviewController {
4247
async createReview(req, res, next) {
4348
try {
4449
// URL 파라미터에서 커미션 신청 ID(requestId)를 추출하고 BigInt로 변환
50+
if (!req.params.requestId) {
51+
throw new RequestIdRequiredError(); // requestId가 누락된 경우 RequestIdRequiredError 반환
52+
}
4553
const requestId = BigInt(req.params.requestId);
4654

4755
// 현재 로그인한 사용자 ID (BigInt 변환)
48-
const userId = BigInt(req.user.id);
56+
const userId = BigInt(req.user.userId);
4957

5058
// 요청 본문 데이터를 DTO 클래스로 구조화
5159
const reviewDto = new ReviewCreateDto(req.body);
@@ -77,10 +85,13 @@ class ReviewController {
7785
async updateReview(req, res, next) {
7886
try {
7987
// URL 파라미터에서 리뷰 ID를 추출하고 BigInt로 변환
88+
if (!req.params.reviewId) {
89+
throw new ReviewIdRequiredError(); // reviewId가 누락된 경우 ReviewIdRequiredError 반환
90+
}
8091
const reviewId = BigInt(req.params.reviewId);
8192

8293
// 현재 로그인한 사용자 ID (BigInt 변환)
83-
const userId = BigInt(req.user.id);
94+
const userId = BigInt(req.user.userId);
8495

8596
// 요청 본문 데이터를 DTO 클래스로 구조화
8697
const reviewDto = new ReviewUpdateDto(req.body);
@@ -112,10 +123,13 @@ class ReviewController {
112123
async deleteReview(req, res, next) {
113124
try {
114125
// URL 파라미터에서 리뷰 ID를 추출하고 BigInt로 변환
126+
if (!req.params.reviewId) {
127+
throw new ReviewIdRequiredError(); // reviewId가 누락된 경우 ReviewIdRequiredError 반환
128+
}
115129
const reviewId = BigInt(req.params.reviewId);
116130

117131
// 현재 로그인한 사용자 ID (BigInt 변환)
118-
const userId = BigInt(req.user.id);
132+
const userId = BigInt(req.user.userId);
119133

120134
// 리뷰 삭제 서비스 호출
121135
const result = await reviewService.deleteReview(reviewId, userId);
@@ -138,7 +152,10 @@ class ReviewController {
138152
*/
139153
async getReviewsByUserId(req, res, next) {
140154
try {
141-
// URL 파라미터에서 사용자 ID 추출
155+
// URL 파라미터에서 사용자 ID를 추출하고 BigInt로 변환
156+
if (!req.params.userId) {
157+
throw new UserIdRequiredError(); // userId가 누락된 경우 UserIdRequiredError 반환
158+
}
142159
const userId = BigInt(req.params.userId);
143160

144161
// 쿼리 파라미터에서 페이지네이션 정보 추출

0 commit comments

Comments
 (0)