Bug fixes
This commit is contained in:
@@ -452,6 +452,8 @@ async def force_finish_marathon(
|
||||
db: DbSession,
|
||||
):
|
||||
"""Force finish a marathon. Admin only."""
|
||||
from app.services.coins import coins_service
|
||||
|
||||
require_admin_with_2fa(current_user)
|
||||
|
||||
result = await db.execute(select(Marathon).where(Marathon.id == marathon_id))
|
||||
@@ -465,6 +467,24 @@ async def force_finish_marathon(
|
||||
old_status = marathon.status
|
||||
marathon.status = MarathonStatus.FINISHED.value
|
||||
marathon.end_date = datetime.utcnow()
|
||||
|
||||
# Award coins for top 3 places (only in certified marathons)
|
||||
if marathon.is_certified:
|
||||
top_result = await db.execute(
|
||||
select(Participant)
|
||||
.options(selectinload(Participant.user))
|
||||
.where(Participant.marathon_id == marathon_id)
|
||||
.order_by(Participant.total_points.desc())
|
||||
.limit(3)
|
||||
)
|
||||
top_participants = top_result.scalars().all()
|
||||
|
||||
for place, participant in enumerate(top_participants, start=1):
|
||||
if participant.total_points > 0:
|
||||
await coins_service.award_marathon_place(
|
||||
db, participant.user, marathon, place
|
||||
)
|
||||
|
||||
await db.commit()
|
||||
|
||||
# Log action
|
||||
|
||||
Reference in New Issue
Block a user