From fadaef7148ff5f4d3c0e8f29e969ee328c96c3be Mon Sep 17 00:00:00 2001 From: BatuhanIlhan Date: Mon, 25 Dec 2023 00:46:34 +0300 Subject: [PATCH] be-745: Fix comment remove bug --- app/backend/src/comment/comment.controller.ts | 4 ++-- app/backend/src/comment/comment.service.ts | 18 +++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/app/backend/src/comment/comment.controller.ts b/app/backend/src/comment/comment.controller.ts index 1cc884c3..5882b4ac 100644 --- a/app/backend/src/comment/comment.controller.ts +++ b/app/backend/src/comment/comment.controller.ts @@ -44,7 +44,7 @@ export class CommentController { return this.commentService.create(createCommentDto,id,request.user.id); } - @Delete(':pollID') + @Delete(':commentID') @UseGuards(AuthGuard, VerificationGuard) @ApiResponse({ status: 201, description: 'Comment removed successfully.' }) @ApiResponse({ @@ -57,7 +57,7 @@ export class CommentController { status: 500, description: 'Internal server error, contact with backend team.', }) - remove(@Param('pollID') id: string , @Req() request : any) { + remove(@Param('commentID') id: string , @Req() request : any) { return this.commentService.remove(id,request.user.id); } } diff --git a/app/backend/src/comment/comment.service.ts b/app/backend/src/comment/comment.service.ts index 66d12248..476f13c1 100644 --- a/app/backend/src/comment/comment.service.ts +++ b/app/backend/src/comment/comment.service.ts @@ -43,21 +43,13 @@ export class CommentService { return await this.commentRepository.save(newLike); } - async remove(pollID: string, userID: string) { - const poll = await this.pollService.findPollById(pollID); - - if (!poll) { - throw new ConflictException('There is no poll with this id'); - } - - const commentToBeDeleted = await this.commentRepository.findOne({ - where: { poll: { id: pollID }, user: { id: userID } }, - }); + async remove(commentID: string, userID: string) { + const comment = await this.commentRepository.findOne({where:{id:commentID}}); - if (!commentToBeDeleted) { - throw new ConflictException('User has not commented on this poll'); + if (!comment) { + throw new ConflictException('There is no comment with this id'); } - return await this.commentRepository.remove(commentToBeDeleted); + return await this.commentRepository.remove(comment); } }