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
34
35
36
37
38
39
40
41
42
# File 'app/controllers/spree/api/v2/operator/check_in_bulks_controller.rb', line 8

def create
  spree_authorize! :create, model_class

  # Optional QR data from a scanned user QR code.
  # - If provided, the system will validate the QR data before check-in.
  # - If omitted, check-in proceeds normally (e.g. manual search by operator).
  # This is only for validating scanned QR codes; operators can always check in guests without it.
  if params[:scanned_user_qr_data].present?
    result = SpreeCmCommissioner::Users::QrData::Verify.call(qr_data: params[:scanned_user_qr_data])
    return render_error_payload(result.error) if result.failure?
  end

  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, check_in_session_id: params[:check_in_session_id] } }
  end

  result = SpreeCmCommissioner::CheckIns::CreateBulk.call(
    check_ins_attributes: check_ins,
    check_in_by: spree_current_user
  )

  if result.success?
    render_serialized_payload(201) do
      collection_serializer.new(
        result.value[:check_ins], { include: resource_includes }
      ).serializable_hash
    end
  else
    render_error_payload(result.error)
  end
end