48 lines
1.2 KiB
Ruby
48 lines
1.2 KiB
Ruby
class Employee
|
|
include SimplyStored::Couch
|
|
include ActiveModel::SerializerSupport
|
|
DEFAULT_SETTINGS = {
|
|
'manager' => false,
|
|
'active' => true,
|
|
'color' => '#3a87ad'
|
|
}
|
|
attr_accessor *DEFAULT_SETTINGS.keys
|
|
attr_reader :settings
|
|
|
|
view :by_confirmation_token, key: :confirmation_token # devise confirmable
|
|
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :confirmable
|
|
property :unconfirmed_email
|
|
|
|
property :name
|
|
#property :email
|
|
|
|
has_many :employee_shifts
|
|
view :by_email, key: :email
|
|
|
|
class << self
|
|
def count_by_email(email)
|
|
database.view by_email(key: email, reduce: true)
|
|
end
|
|
def default_settings
|
|
DEFAULT_SETTINGS
|
|
end
|
|
end
|
|
|
|
#validates :email, email: true
|
|
has_and_belongs_to_many :suppliers, storing_keys: false
|
|
has_many :orders
|
|
has_and_belongs_to_many :lists, storing_keys: false
|
|
|
|
def enrich_with_settings(settings)
|
|
@settings = settings
|
|
settings.settings.each do |attribute, value|
|
|
public_send "#{attribute}=", value
|
|
end
|
|
settings
|
|
end
|
|
|
|
def settings
|
|
@settings || SupplierEmployeesSettings.new(Supplier.new).for_employee(self)
|
|
end
|
|
end
|