38 lines
1.2 KiB
Ruby
38 lines
1.2 KiB
Ruby
class Poll
|
|
class Officer < ApplicationRecord
|
|
belongs_to :user
|
|
has_many :officer_assignments, class_name: "Poll::OfficerAssignment"
|
|
has_many :shifts, class_name: "Poll::Shift"
|
|
has_many :failed_census_calls, foreign_key: :poll_officer_id
|
|
|
|
validates :user_id, presence: true, uniqueness: true
|
|
|
|
def name
|
|
user&.name || I18n.t("shared.author_info.author_deleted")
|
|
end
|
|
|
|
def email
|
|
user&.email || I18n.t("shared.author_info.email_deleted")
|
|
end
|
|
|
|
def voting_days_assigned_polls
|
|
officer_assignments.voting_days.includes(booth_assignment: :poll).
|
|
map(&:booth_assignment).
|
|
map(&:poll).uniq.compact.
|
|
sort { |x, y| y.ends_at <=> x.ends_at }
|
|
end
|
|
|
|
def final_days_assigned_polls
|
|
officer_assignments.final.includes(booth_assignment: :poll).
|
|
map(&:booth_assignment).
|
|
map(&:poll).uniq.compact.
|
|
sort { |x, y| y.ends_at <=> x.ends_at }
|
|
end
|
|
|
|
def todays_booths
|
|
officer_assignments.by_date(Date.current).map(&:booth).uniq
|
|
end
|
|
|
|
end
|
|
end
|