fix(lobby): avoid orphaned round configs on round start
This commit is contained in:
@@ -528,23 +528,25 @@ def start_round(request: HttpRequest, code: str) -> JsonResponse:
|
||||
status=400,
|
||||
)
|
||||
|
||||
round_config, created = RoundConfig.objects.get_or_create(
|
||||
session=session,
|
||||
number=session.current_round,
|
||||
defaults={"category": category},
|
||||
)
|
||||
if not created:
|
||||
if RoundConfig.objects.filter(session=session, number=session.current_round).exists():
|
||||
return api_error(
|
||||
request,
|
||||
code="round_already_configured",
|
||||
status=409,
|
||||
)
|
||||
|
||||
round_config = RoundConfig(
|
||||
session=session,
|
||||
number=session.current_round,
|
||||
category=category,
|
||||
)
|
||||
|
||||
try:
|
||||
round_question = _select_round_question(session, round_config)
|
||||
except ValueError as exc:
|
||||
return api_error(request, code=str(exc), status=400)
|
||||
|
||||
round_config.save()
|
||||
session.status = GameSession.Status.LIE
|
||||
session.save(update_fields=["status"])
|
||||
|
||||
@@ -1101,22 +1103,24 @@ def start_next_round(request: HttpRequest, code: str) -> JsonResponse:
|
||||
if previous_round_config is None:
|
||||
return api_error(request, code="round_config_missing", status=400)
|
||||
|
||||
locked_session.current_round += 1
|
||||
next_round_config = RoundConfig.objects.create(
|
||||
next_round_number = locked_session.current_round + 1
|
||||
next_round_config = RoundConfig(
|
||||
session=locked_session,
|
||||
number=locked_session.current_round,
|
||||
number=next_round_number,
|
||||
category=previous_round_config.category,
|
||||
lie_seconds=previous_round_config.lie_seconds,
|
||||
guess_seconds=previous_round_config.guess_seconds,
|
||||
points_correct=previous_round_config.points_correct,
|
||||
points_bluff=previous_round_config.points_bluff,
|
||||
)
|
||||
locked_session.current_round = next_round_number
|
||||
|
||||
try:
|
||||
round_question = _select_round_question(locked_session, next_round_config)
|
||||
except ValueError as exc:
|
||||
return api_error(request, code=str(exc), status=400)
|
||||
|
||||
next_round_config.save()
|
||||
locked_session.status = GameSession.Status.LIE
|
||||
locked_session.save(update_fields=["current_round", "status"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user