Class: SpreeCmCommissioner::GuestSeatUpdater
- Inherits:
-
BaseInteractor
- Object
- BaseInteractor
- SpreeCmCommissioner::GuestSeatUpdater
- Defined in:
- app/models/concerns/spree_cm_commissioner/guest_seat_updater.rb
Instance Method Summary collapse
- #block_belongs_to_variant?(block_id, variant_id) ⇒ Boolean
- #call ⇒ Object
- #update_seat_for_guest ⇒ Object
Instance Method Details
#block_belongs_to_variant?(block_id, variant_id) ⇒ Boolean
39 40 41 42 43 |
# File 'app/models/concerns/spree_cm_commissioner/guest_seat_updater.rb', line 39 def block_belongs_to_variant?(block_id, variant_id) return false unless block_id.present? && variant_id.present? SpreeCmCommissioner::VariantBlock.exists?(variant_id: variant_id, block_id: block_id) end |
#call ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/concerns/spree_cm_commissioner/guest_seat_updater.rb', line 8 def call context.fail!(errors: 'Updated user is required') if updated_by.blank? context.fail!(errors: 'Line item not found') unless line_item context.fail!(errors: 'Guest not found') unless guest context.fail!(errors: 'Block ID is required') if block_id.blank? if block_id.present? && !block_belongs_to_variant?(block_id, line_item.variant_id) context.fail!(errors: "Variant change is not allowed — seat can only be updated for the same variant #{line_item.variant_id}") end ActiveRecord::Base.transaction do update_seat_for_guest end rescue StandardError => e raise if defined?(Interactor::Failure) && e.is_a?(Interactor::Failure) context.fail!(errors: e.) end |
#update_seat_for_guest ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/concerns/spree_cm_commissioner/guest_seat_updater.rb', line 27 def update_seat_for_guest reserve_block = SpreeCmCommissioner::ReservedBlock.find_by( guest_id: guest.id, block_id: guest.block_id ) reserve_block.update!(block_id: block_id, updated_by_id: updated_by.id) if reserve_block && reserve_block.block_id != block_id guest.update!(block_id: block_id) if guest.block_id != block_id && block_id.present? line_item end |