Skip to content

Commit

Permalink
Fix user stats subtraction upon deleting seasons and sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
BGMP committed Jan 22, 2024
1 parent 8d6a9e9 commit 59ae33d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
4 changes: 0 additions & 4 deletions app/controllers/rankings_controller.rb
Expand Up @@ -67,12 +67,8 @@ def update

# DELETE /rankings/1 or /rankings/1.json
def destroy
sessions = @ranking.sessions

respond_to do |format|
if @ranking.destroy!
sessions.each(&destroy)

format.html { redirect_to rankings_url, :notice => 'Ranking was successfully deleted.' }
format.json { head :no_content }
else
Expand Down
27 changes: 22 additions & 5 deletions app/controllers/seasons_controller.rb
Expand Up @@ -71,17 +71,34 @@ def update

# DELETE /seasons/1 or /seasons/1.json
def destroy
require 'rva_calculate_results_service'
require 'stats_service'
require 'team_points_service'

@season.rankings.each do |r|
r.sessions.each(&:destroy)
r.sessions.each do |s|

rva_results = RvaCalculateResultsService.new(s).call

if s.teams?
TeamPointsService.new(s, rva_results).remove_team_points
else
StatsService.new(s, rva_results).remove_stats
end

Rails.cache.delete("Session:#{s.id}")

s.destroy!
end

r.destroy!
end

@season.tracks.each(&:destroy)
@season.cars.each(&:destroy)

respond_to do |format|
if @season.destroy!
rankings.each(&destroy)
tracks.each(&destroy)
cars.each(&destroy)

format.html { redirect_to seasons_url, :notice => 'Season was successfully deleted.' }
format.json { head :no_content }
else
Expand Down
16 changes: 7 additions & 9 deletions app/controllers/sessions_controller.rb
Expand Up @@ -71,18 +71,16 @@ def destroy
require 'stats_service'
require 'team_points_service'

session = Session.new(@session.attributes) # copy
rva_results = RvaCalculateResultsService.new(@session).call

if @session.teams?
TeamPointsService.new(@session, rva_results).remove_team_points
else
StatsService.new(@session, rva_results).remove_stats
end

respond_to do |format|
if @session.destroy!
rva_results = RvaCalculateResultsService.new(session).call

if session.teams?
TeamPointsService.new(session, rva_results).remove_team_points
else
StatsService.new(session, rva_results).remove_stats
end

format.html { redirect_to sessions_url, :notice => 'Session was successfully deleted.' }
format.json { head :no_content }

Expand Down

0 comments on commit 59ae33d

Please sign in to comment.