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

Added pages for teampointsadjust and spearated wrestler and school deducted points

This commit is contained in:
2016-01-12 17:36:45 +00:00
parent 227e588658
commit c6626988db
9 changed files with 148 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
class School < ActiveRecord::Base
belongs_to :tournament, touch: true
has_many :wrestlers, dependent: :destroy
has_many :deductedPoints, through: :wrestlers
has_many :deductedPoints, class_name: "Teampointadjust"
has_many :delegates, class_name: "SchoolDelegate"
validates :name, presence: true
@@ -33,9 +33,14 @@ class School < ActiveRecord::Base
def totalDeductedPoints
points = 0
self.deductedPoints.each do |d|
deductedPoints.each do |d|
points = points + d.points
end
self.wrestlers.each do |w|
w.deductedPoints.each do |d|
points = points + d.points
end
end
points
end
end

View File

@@ -1,7 +1,28 @@
class Teampointadjust < ActiveRecord::Base
belongs_to :wrestler
belongs_to :school
after_save do
self.wrestler.lastFinishedMatch.advance_wrestlers
after_save do
advance_wrestlers_and_calc_team_score
end
after_destroy do
advance_wrestlers_and_calc_team_score
end
def advance_wrestlers_and_calc_team_score
#Team score needs calculated
if self.wrestler_id != nil
#In case this affects pool order
if self.wrestler.lastFinishedMatch
self.wrestler.lastFinishedMatch.advance_wrestlers
end
self.wrestler.school.calcScore
elsif self.school_id != nil
self.school.calcScore
end
end
if Rails.env.production?
handle_asynchronously :advance_wrestlers_and_calc_team_score
end
end

View File

@@ -86,4 +86,19 @@ class Tournament < ActiveRecord::Base
m.save
end
end
def pointAdjustments
point_adjustments = []
self.schools.each do |s|
s.deductedPoints.each do |d|
point_adjustments << d
end
end
self.wrestlers.each do |w|
w.deductedPoints.each do |d|
point_adjustments << d
end
end
point_adjustments
end
end