Class: Spree::Api::V2::Operator::CheckInBulksController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/api/v2/operator/check_in_bulks_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/spree/api/v2/operator/check_in_bulks_controller.rb', line 8

def create
  spree_authorize! :create, model_class

  check_ins = []

  if params[:check_ins].present?
    check_ins = process_check_ins(params[:check_ins])
  elsif params[:guest_ids].present?
    check_ins = params[:guest_ids].map { |guest_id| { guest_id: guest_id } }
  end

  context = SpreeCmCommissioner::CheckInBulkCreator.call(
    check_ins_attributes: check_ins,
    check_in_by: spree_current_user
  )

  if context.success?
    render_serialized_payload(201) do
      collection_serializer.new(
        context.check_ins, { include: resource_includes }
      ).serializable_hash
    end
  else
    render_error_payload(context.message)
  end
end