Fix events

This commit is contained in:
2026-01-05 23:41:22 +07:00
parent 65b2512d8c
commit 18fe95effc
5 changed files with 99 additions and 29 deletions

View File

@@ -1335,17 +1335,31 @@ async def complete_bonus_assignment(
bonus_assignment.proof_url = proof_url
# Complete the bonus assignment
# NOTE: We store BASE points here. Event multiplier is applied when main assignment is completed
# This ensures multiplier is applied to the SUM (base + all bonuses), not separately
bonus_assignment.points_earned = bonus_assignment.challenge.points
bonus_assignment.status = BonusAssignmentStatus.COMPLETED.value
bonus_assignment.proof_comment = comment
bonus_assignment.points_earned = bonus_assignment.challenge.points
bonus_assignment.completed_at = datetime.utcnow()
# If main assignment is already COMPLETED, add bonus points immediately
# This handles the case where a bonus was disputed and user is re-completing it
if assignment.status == AssignmentStatus.COMPLETED.value:
from app.models import EventType
from app.services.points import PointsService
# Apply event multiplier if assignment had one
points_to_add = bonus_assignment.points_earned
if assignment.event_type:
ps = PointsService()
multiplier = ps.EVENT_MULTIPLIERS.get(assignment.event_type, 1.0)
points_to_add = int(bonus_assignment.points_earned * multiplier)
# Update bonus assignment to show multiplied points
bonus_assignment.points_earned = points_to_add
participant = assignment.participant
participant.total_points += bonus_assignment.points_earned
assignment.points_earned += bonus_assignment.points_earned
participant.total_points += points_to_add
assignment.points_earned += points_to_add
# NOTE: If main is not completed yet, points will be added when main is completed
# This prevents exploiting by dropping the main assignment after getting bonus points