Class: SpreeCmCommissioner::CheckIns::DestroyBulk

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/check_ins/destroy_bulk.rb

Instance Method Summary collapse

Instance Method Details

#call(check_ins_attributes:, destroyed_by: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/spree_cm_commissioner/check_ins/destroy_bulk.rb', line 6

def call(check_ins_attributes:, destroyed_by: nil)
  return failure(:guest_ids_must_not_blank) if check_ins_attributes.blank?

  check_ins = []

  ActiveRecord::Base.transaction do
    check_ins = check_ins_attributes.map do |attrs|
      guest = SpreeCmCommissioner::Guest.find(attrs[:guest_id])
      destroy_check_in!(guest, attrs, destroyed_by)
    end.compact

    success(check_ins: check_ins)
  end
rescue ActiveRecord::RecordNotFound => e
  failure(:record_not_found, e.message)
rescue ActiveRecord::RecordInvalid => e
  failure(:invalid_record, e.record.errors.full_messages.join(', '))
rescue StandardError => e
  failure(:failed_to_destroy_check_ins, e.message)
end