Class: Spree::Api::V2::Operator::EventChartsController

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

Constant Summary collapse

ACCEPTED_KYC_FIELDS =
%i[guest_gender guest_occupation guest_nationality].freeze
ADDITIONAL_FIELDS =
%i[participation entry_type].freeze

Instance Method Summary collapse

Instance Method Details

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/spree/api/v2/operator/event_charts_controller.rb', line 9

def index
  resources = if restricted?
                []
              else
                kyc_fields = fetch_filtered_kyc_fields
                types = ADDITIONAL_FIELDS + kyc_fields

                types.map do |type|
                  # Create unique ID by using chart_type as the identifier
                  SpreeCmCommissioner::EventChart.new(
                    id: type.to_s,
                    chart_type: type,
                    product_charts: nil
                  )
                end
              end

  render json: SpreeCmCommissioner::V2::Operator::PieChartEventAggregatorSerializer.new(resources).serializable_hash
end

#resourceObject



29
30
31
32
33
34
35
# File 'app/controllers/spree/api/v2/operator/event_charts_controller.rb', line 29

def resource
  @resource = if restricted?
                SpreeCmCommissioner::EventChart.new(id: params[:id], chart_type: params[:id] || 'participation', product_charts: [])
              else
                event_chart_aggregator_queries.call
              end
end

#resource_serializerObject



37
38
39
# File 'app/controllers/spree/api/v2/operator/event_charts_controller.rb', line 37

def resource_serializer
  SpreeCmCommissioner::V2::Operator::PieChartEventAggregatorSerializer
end