Skip to content

Commit

Permalink
Merge pull request #746 from bounswe/be-745/fix_comment_remove_bug
Browse files Browse the repository at this point in the history
be-745: Fix comment remove bug
  • Loading branch information
Alputer authored Dec 24, 2023
2 parents 837079b + fadaef7 commit f2c327a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/backend/src/comment/comment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);
}
}
Expand Down
18 changes: 5 additions & 13 deletions app/backend/src/comment/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit f2c327a

Please sign in to comment.