diff --git a/src/common/errors/notification.errors.js b/src/common/errors/notification.errors.js index 3ecf5e1..57e5e3c 100644 --- a/src/common/errors/notification.errors.js +++ b/src/common/errors/notification.errors.js @@ -120,4 +120,26 @@ export class PushTokenAlreadyExistsError extends BaseError { data }); } +} + +export class NotificationIdRequiredError extends BaseError { + constructor(data = null) { + super({ + errorCode: "N012", + reason: "notificationId가 필요합니다", + statusCode: 400, + data + }); + } +} + +export class TargetUserIdRequiredError extends BaseError { + constructor(data = null) { + super({ + errorCode: "N013", + reason: "target_user_id가 필요합니다", + statusCode: 400, + data + }); + } } \ No newline at end of file diff --git a/src/common/errors/review.errors.js b/src/common/errors/review.errors.js index db1ae29..31640d3 100644 --- a/src/common/errors/review.errors.js +++ b/src/common/errors/review.errors.js @@ -33,17 +33,6 @@ export class ReviewContentTooShortError extends BaseError { } } -export class ReviewContentTooLongError extends BaseError { - constructor(data = null) { - super({ - errorCode: "R011", - reason: "리뷰 내용이 1000자를 초과합니다", - statusCode: 400, // Bad Request - data, - }); - } -} - export class RequestNotFoundError extends BaseError { constructor(data = null) { super({ @@ -119,4 +108,48 @@ export class ReviewRatingInvalidError extends BaseError { data, }); } +} + +export class ReviewContentTooLongError extends BaseError { + constructor(data = null) { + super({ + errorCode: "R011", + reason: "리뷰 내용이 1000자를 초과합니다", + statusCode: 400, // Bad Request + data, + }); + } +} + +export class RequestIdRequiredError extends BaseError { + constructor(data = null) { + super({ + errorCode: "R012", + reason: "requestId가 필요합니다", + statusCode: 400, // Bad Request + data, + }); + } +} + +export class ReviewIdRequiredError extends BaseError { + constructor(data = null) { + super({ + errorCode: "R013", + reason: "reviewId가 필요합니다", + statusCode: 400, // Bad Request + data, + }); + } +} + +export class UserIdRequiredError extends BaseError { + constructor(data = null) { + super({ + errorCode: "R014", + reason: "userId가 필요합니다", + statusCode: 400, // Bad Request + data, + }); + } } \ No newline at end of file diff --git a/src/notification/controller/notification.controller.js b/src/notification/controller/notification.controller.js index 3132777..a42f6f2 100644 --- a/src/notification/controller/notification.controller.js +++ b/src/notification/controller/notification.controller.js @@ -1,12 +1,14 @@ import { StatusCodes } from "http-status-codes"; -import notificationService from '../service/notification.service.js'; import { stringifyWithBigInt } from "../../bigintJson.js"; import { - NotificationListResponseDto, - NotificationReadResponseDto, + NotificationIdRequiredError +} from '../../common/errors/notification.errors.js'; +import { NotificationDeleteResponseDto, - NotificationListItemDto + NotificationListResponseDto, + NotificationReadResponseDto } from '../dto/notification.dto.js'; +import notificationService from '../service/notification.service.js'; class NotificationController { @@ -49,6 +51,9 @@ class NotificationController { async markNotificationAsRead(req, res, next) { try { // URL 파라미터에서 알림 ID를 추출하고 BigInt로 변환 + if (!req.params.notificationId) { + throw new NotificationIdRequiredError(); // notificationId가 누락된 경우 NotificationIdRequiredError 반환 + } const notificationId = BigInt(req.params.notificationId); // 현재 로그인한 사용자 ID diff --git a/src/notification/fcm/controller/push.controller.js b/src/notification/fcm/controller/push.controller.js index 7cee2f8..fc59113 100644 --- a/src/notification/fcm/controller/push.controller.js +++ b/src/notification/fcm/controller/push.controller.js @@ -1,11 +1,14 @@ import { StatusCodes } from "http-status-codes"; import { stringifyWithBigInt } from "../../../bigintJson.js"; import { + TargetUserIdRequiredError +} from '../../../common/errors/notification.errors.js'; +import { + PushSendResponseDto, PushTokenDeleteResponseDto, PushTokenRegisterDto, PushTokenResponseDto, - TestPushRequestDto, - PushSendResponseDto + TestPushRequestDto } from '../dto/push.dto.js'; import pushService from '../service/push.service.js'; @@ -79,6 +82,9 @@ class PushController { const testPushDto = new TestPushRequestDto(req.body); // 대상 사용자 ID 추출 + if (!testPushDto.target_user_id) { + throw new TargetUserIdRequiredError(); // target_user_id가 누락된 경우 TargetUserIdRequiredError 반환 + } const targetUserId = BigInt(testPushDto.target_user_id); // 테스트 Push 발송 서비스 호출 diff --git a/src/review/controller/review.controller.js b/src/review/controller/review.controller.js index f9b39cf..411dcf0 100644 --- a/src/review/controller/review.controller.js +++ b/src/review/controller/review.controller.js @@ -1,13 +1,18 @@ import { StatusCodes } from "http-status-codes"; -import reviewService from '../service/review.service.js'; import { stringifyWithBigInt } from "../../bigintJson.js"; import { + RequestIdRequiredError, + ReviewIdRequiredError, + UserIdRequiredError +} from '../../common/errors/review.errors.js'; +import { + ImageUploadResponseDto, ReviewCreateDto, - ReviewUpdateDto, + ReviewListResponseDto, ReviewResponseDto, - ImageUploadResponseDto, - ReviewListResponseDto + ReviewUpdateDto } from '../dto/review.dto.js'; // DTO 클래스 import +import reviewService from '../service/review.service.js'; class ReviewController { @@ -42,10 +47,13 @@ class ReviewController { async createReview(req, res, next) { try { // URL 파라미터에서 커미션 신청 ID(requestId)를 추출하고 BigInt로 변환 + if (!req.params.requestId) { + throw new RequestIdRequiredError(); // requestId가 누락된 경우 RequestIdRequiredError 반환 + } const requestId = BigInt(req.params.requestId); // 현재 로그인한 사용자 ID (BigInt 변환) - const userId = BigInt(req.user.id); + const userId = BigInt(req.user.userId); // 요청 본문 데이터를 DTO 클래스로 구조화 const reviewDto = new ReviewCreateDto(req.body); @@ -77,10 +85,13 @@ class ReviewController { async updateReview(req, res, next) { try { // URL 파라미터에서 리뷰 ID를 추출하고 BigInt로 변환 + if (!req.params.reviewId) { + throw new ReviewIdRequiredError(); // reviewId가 누락된 경우 ReviewIdRequiredError 반환 + } const reviewId = BigInt(req.params.reviewId); // 현재 로그인한 사용자 ID (BigInt 변환) - const userId = BigInt(req.user.id); + const userId = BigInt(req.user.userId); // 요청 본문 데이터를 DTO 클래스로 구조화 const reviewDto = new ReviewUpdateDto(req.body); @@ -112,10 +123,13 @@ class ReviewController { async deleteReview(req, res, next) { try { // URL 파라미터에서 리뷰 ID를 추출하고 BigInt로 변환 + if (!req.params.reviewId) { + throw new ReviewIdRequiredError(); // reviewId가 누락된 경우 ReviewIdRequiredError 반환 + } const reviewId = BigInt(req.params.reviewId); // 현재 로그인한 사용자 ID (BigInt 변환) - const userId = BigInt(req.user.id); + const userId = BigInt(req.user.userId); // 리뷰 삭제 서비스 호출 const result = await reviewService.deleteReview(reviewId, userId); @@ -138,7 +152,10 @@ class ReviewController { */ async getReviewsByUserId(req, res, next) { try { - // URL 파라미터에서 사용자 ID 추출 + // URL 파라미터에서 사용자 ID를 추출하고 BigInt로 변환 + if (!req.params.userId) { + throw new UserIdRequiredError(); // userId가 누락된 경우 UserIdRequiredError 반환 + } const userId = BigInt(req.params.userId); // 쿼리 파라미터에서 페이지네이션 정보 추출