Files
baclight/app/models/member.rb
T
2026-07-23 10:32:51 -04:00

47 lines
1.3 KiB
Ruby

class Member < ApplicationRecord
include MemberAutomation
belongs_to :id_card_plan, class_name: 'IdCard::Plan', optional: true
belongs_to :employer
serialize :dependents, coder: JSON
validates :pb_entity_key, presence: true
validates :name, :family_id, :mb_member_key, :pl_plan_key,
:id_card_display_name, presence: true, unless: :new_record?
validates :division, presence: true, if: -> { employer.id_card_setup.has_divisions }
# validates :coverage_class, :dental_plan_key, presence: true, if: -> { employer.id_card_setup.has_dental }
validates :mb_member_key, :pb_entity_key, uniqueness: true
# validates :name, uniqueness: { scope: :employer_id }
before_validation :format_dependents, if: :dependents_changed?
scope :active, -> {
where(active: true)
}
def id_card_field_exception_values
address = Vhcs::PbEntityAddress.find_by(pb_entity_key: pb_entity_key)
{
zipcode: address.zip,
state: address.state,
family_id: family_id
}
end
def member_key
{
pl_plan_key: pl_plan_key,
member_keys: [pb_entity_key]
}
end
private
def format_dependents
if self.dependents.is_a?(String)
self.dependents = self.dependents.split(",").map(&:strip)
end
end
end