Skip to content

Commit

Permalink
Merge pull request #13 from wang-bam-bbang/comment
Browse files Browse the repository at this point in the history
chore: add badrequest exception when create comment
  • Loading branch information
Kimcheolhui authored Dec 9, 2024
2 parents 5115459 + edde2b2 commit 62f3019
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/comment/comment.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
BadRequestException,
ForbiddenException,
Injectable,
NotFoundException,
Expand All @@ -19,14 +20,21 @@ export class CommentService {
userUuid: string,
createCommentDto: CreateCommentDto,
): Promise<CommentResponseDto> {
const { postId, parentId } = createCommentDto;
const { postId, parentId, type } = createCommentDto;

if (type === 'COMMENT' && parentId) {
throw new BadRequestException("COMMENT don't need parentId");
}
if (type === 'REPLY' && !parentId) {
throw new BadRequestException('REPLY need parentId');
}

const post = await this.postService.getPostById(postId);
if (!post) {
throw new NotFoundException('Post not found');
}

if (parentId) {
if (type === 'REPLY') {
const parentComment =
await this.commentRepository.getCommentById(parentId);
if (!parentComment) {
Expand Down

0 comments on commit 62f3019

Please sign in to comment.