Class: RestaurantGroup

Inherits:
ApplicationRecord show all
Includes:
FriendlyId, HungryHub::DynamicTime, IdentityCache, TypesOfActor
Defined in:
app/models/restaurant_group.rb

Overview

to login to Dashboard Group /dashboard/v2/group/sign_in

Instance Method Summary collapse

Methods included from HungryHub::DynamicTime

#time_zone

Methods included from TypesOfActor

#kinda_like_owner?, #owner?, #restaurant_group?, #staff?, #user?

Methods inherited from ApplicationRecord

sync_carrierwave_url

Instance Method Details

#authenticate(password) ⇒ Object



55
56
57
# File 'app/models/restaurant_group.rb', line 55

def authenticate(password)
  valid_password? password
end

#create_staffObject



59
60
61
62
63
# File 'app/models/restaurant_group.rb', line 59

def create_staff
  partner_service = PartnerService::Staff::CreateFromOwner.new(self)
  partner_service.password = password
  partner_service.call
end

#reservationsObject

Mimic owner , used in Dashboard::V2::ReportsController



51
52
53
# File 'app/models/restaurant_group.rb', line 51

def reservations
  ::Reservation.where(restaurant_id: restaurants.pluck(:id)).exclude_temporary
end

#staff_accountObject

this is main staff account for the restaurant group



66
67
68
# File 'app/models/restaurant_group.rb', line 66

def 
  Staff.find_by(email: email)
end

#to_paramObject



42
43
44
# File 'app/models/restaurant_group.rb', line 42

def to_param
  id
end

#to_url_hashObject



46
47
48
# File 'app/models/restaurant_group.rb', line 46

def to_url_hash
  HungryHub::RestaurantGroup::Codec.encode(id)
end

#update_staffObject

keep the staff account in sync with the restaurant group



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/models/restaurant_group.rb', line 75

def update_staff
  # Skip if this is triggered by a staff update to prevent recursion
  return if @skip_staff_update

  staff = if email_changed?
            Staff.find_by(email: email_was)
          else
            
          end
  return if staff.blank?

  if password.present?
    # Set a flag on the staff to prevent it from updating this restaurant group again
    staff.instance_variable_set(:@skip_password_sync, true)
    staff.password = password
    staff.audit_comment = "Password synchronized from RestaurantGroup ID: #{id}"
  end

  if email.present?
    staff.email = email
    staff.audit_comment = "Email synchronized from RestaurantGroup ID: #{id}" unless staff.audit_comment
  end

  staff.restaurant_group = self
  staff.save
end