Skip to content

Commit

Permalink
fix: update logic challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskorbakov committed Oct 27, 2024
1 parent 1f0c0c8 commit bd75348
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function team(int $id): array

public function challenge(int $id): array
{
$challenges = User::query()->findOrFail($id);
$challenges = User::query()->find($id);

return $this->userService->challenge($challenges);
}
Expand Down
10 changes: 7 additions & 3 deletions app/Services/Api/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ public function teamIsCaptain(User $user): array
return UserTeamDTO::collect($team)->toArray();
}

public function challenge(User $user): array
public function challenge(User|null $user): array
{
$challenges = $user->challenges()->orderBy('end_date', 'desc')->get();
if($user) {
$challenges = $user->challenges()->orderBy('end_date', 'desc')->get();

return UserChallengeDTO::collect($challenges)->toArray();
}

return UserChallengeDTO::collect($challenges)->toArray();
return [];
}
}

0 comments on commit bd75348

Please sign in to comment.