Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
get only comment pending without parent or a parent accepted.
Browse files Browse the repository at this point in the history
  • Loading branch information
Capryc0rne committed May 6, 2024
1 parent f312833 commit 673cf7e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions backend/app/Http/Controllers/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,18 @@ public function reject($id)
*/
public function pending()
{
$comments = Comment::where('id_status', self::PENDING)->get();
return response()->json(['comments' => $comments->map(fn($comment) => self::formatComment($comment))]);
$comments = Comment::where('id_status', self::PENDING)
->where(function ($query) {
$query->whereNull('id_parent')
->orWhereIn('id_parent', function ($query) {
$query->select('id_comment')
->from('comments')
->where('id_status', self::ACCEPTED);
});
})
->get();

return response()->json(['comments' => $comments->map(fn($comment) => $this->formatComment($comment))]);
}

/**
Expand Down

0 comments on commit 673cf7e

Please sign in to comment.