1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Added a daily recurring job to cleanup tournaments. Fixed final score fields not loading without page refresh on mat stats page and added a cypress test for it.

This commit is contained in:
2025-05-07 16:01:48 -04:00
parent 2856060b11
commit 4accedbb43
16 changed files with 343 additions and 104 deletions

View File

@@ -0,0 +1,36 @@
class TournamentCleanupJob < ApplicationJob
queue_as :default
def perform
# Remove or clean up tournaments based on age and match status
process_old_tournaments
end
private
def process_old_tournaments
# Get all tournaments older than 1 week that have a user_id
old_tournaments = Tournament.where('date < ? AND user_id IS NOT NULL', 1.week.ago.to_date)
old_tournaments.each do |tournament|
# Check if it has any non-BYE finished matches
has_real_matches = tournament.matches.where(finished: 1).where.not(win_type: 'BYE').exists?
if has_real_matches
# 1. Remove all school delegates
tournament.schools.each do |school|
school.delegates.destroy_all
end
# 2. Remove all tournament delegates
tournament.delegates.destroy_all
# 3. Set user_id to null
tournament.update(user_id: nil)
else
tournament.destroy
end
end
end
end