recruitment/app/models/recruit_profile.rb

62 lines
1.4 KiB
Ruby
Raw Normal View History

2017-12-21 19:41:50 +00:00
class RecruitProfile
include Mongoid::Document
include Mongoid::Timestamps
2018-01-01 13:52:15 +00:00
include Slug
2017-12-21 19:41:50 +00:00
EMPLOYEE=1
EMPLOYER=2
field :pseudo_member_id
field :email
2018-01-01 13:52:15 +00:00
field :first_name, as: :slug_title
2017-12-21 19:41:50 +00:00
field :last_name
field :user_type, type: Integer, default: 1
2018-01-17 18:22:24 +00:00
field :enabled, type: Boolean, :default => true
2017-12-21 19:41:50 +00:00
scope :employers, ->{ where(user_type: self::EMPLOYER) }
scope :employees, ->{ where(user_type: self::EMPLOYEE) }
has_one :employee_profile, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :employee_profile, :allow_destroy => true
has_one :employer_profile, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :employer_profile, :allow_destroy => true
2018-01-17 18:22:24 +00:00
def disable_user
pu = PseudoUser.where(:user_name => self.pseudo_member_id).first
pu.enabled = false
self.enabled = false
pu.save
self.save
end
def enable_user
pu = PseudoUser.where(:user_name => self.pseudo_member_id).first
pu.enabled = true
self.enabled = true
pu.save
self.save
end
2017-12-21 19:41:50 +00:00
def name
self.first_name + " " + self.last_name rescue self.email
end
def profile
if self.is_employer?
self.employer_profile
elsif self.is_employee?
self.employee_profile
end
end
def is_employer?
self.user_type == RecruitProfile::EMPLOYER
end
def is_employee?
self.user_type == RecruitProfile::EMPLOYEE
end
end