Class: RestaurantGroup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- RestaurantGroup
- 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
- #authenticate(password) ⇒ Object
- #create_staff ⇒ Object
-
#reservations ⇒ Object
Mimic owner , used in Dashboard::V2::ReportsController.
-
#staff_account ⇒ Object
this is main staff account for the restaurant group.
- #to_param ⇒ Object
- #to_url_hash ⇒ Object
-
#update_staff ⇒ Object
keep the staff account in sync with the restaurant group.
Methods included from HungryHub::DynamicTime
Methods included from TypesOfActor
#kinda_like_owner?, #owner?, #restaurant_group?, #staff?, #user?
Methods inherited from ApplicationRecord
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_staff ⇒ Object
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 |
#reservations ⇒ Object
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_account ⇒ Object
this is main staff account for the restaurant group
66 67 68 |
# File 'app/models/restaurant_group.rb', line 66 def staff_account Staff.find_by(email: email) end |
#to_param ⇒ Object
42 43 44 |
# File 'app/models/restaurant_group.rb', line 42 def to_param id end |
#to_url_hash ⇒ Object
46 47 48 |
# File 'app/models/restaurant_group.rb', line 46 def to_url_hash HungryHub::RestaurantGroup::Codec.encode(id) end |
#update_staff ⇒ Object
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 staff_account 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 |