public function swapGroup(User $user, Round $round)
{
$result = $user->findResult($round);
- return $result && !$round->locked;
+ if (!$result || $round->locked || $round->tournament->locked) {
+ return false;
+ }
+ $remaining = $round->tournament->rounds()
+ ->where('number', '=', $round->number)
+ ->where('group', '!=', $round->group)
+ ->whereDoesntHave('results', function ($query) use ($user) {
+ $query->where('user_id', '=', $user->id);
+ })
+ ->count();
+ return $remaining > 0;
}
}
};
export const maySwapGroup = (user, tournament, round, result) => {
- return user && result && tournament?.group_size > 1 && !tournament.locked && round && !round.locked;
+ if (!user || !result || tournament?.group_size <= 1 || tournament.locked || !tournament?.rounds || !round || round.locked) {
+ return false;
+ }
+ const remaining_rounds = tournament.rounds.filter(
+ (r) => r.number === round.number && r.group !== round.group && !User.findResult(user, r),
+ );
+ return remaining_rounds.length > 0;
};
export const mayModifyResults = (user, tournament, round) => {