Class: Spree::Api::V2::Operator::CheckInsController

Inherits:
ResourceController
  • Object
show all
Includes:
SpreeCmCommissioner::Operator::EventAuthorization
Defined in:
app/controllers/spree/api/v2/operator/check_ins_controller.rb

Constant Summary collapse

CACHE_EXPIRES_IN =

Check-in history data requires fresh/recent data for operator dashboards Short cache duration ensures operators see near real-time check-in activity

1.minute

Instance Method Summary collapse

Instance Method Details

#collection ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/spree/api/v2/operator/check_ins_controller.rb', line 14

def collection
  @collection ||= if restricted?
                    SpreeCmCommissioner::CheckIn.none
                  else
                    SpreeCmCommissioner::CheckIn
                      .where(checkinable_type: 'Spree::Taxon', checkinable_id: params[:taxon_id])
                      .page(params[:page])
                      .per(params[:per_page])
                  end
end

#collection_cache_opts ⇒ Object

override



26
27
28
29
30
31
# File 'app/controllers/spree/api/v2/operator/check_ins_controller.rb', line 26

def collection_cache_opts
  {
    namespace: Spree::Api::Config[:api_v2_collection_cache_namespace],
    expires_in: CACHE_EXPIRES_IN
  }
end

#create ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/spree/api/v2/operator/check_ins_controller.rb', line 33

def create
  spree_authorize! :create, model_class

  result = SpreeCmCommissioner::CheckIns::CreateBulk.call(
    check_ins_attributes: [{ guest_id: params[:guest_id], check_in_session_id: params[:check_in_session_id] }],
    check_in_by: spree_current_user
  )

  if result.success?
    render_serialized_payload(201) { serialize_resource(result.value[:check_ins][0]) }
  else
    render_error_payload(result.error)
  end
end