Class: Spree::Api::V3::Admin::PromotionActionsController
- Inherits:
-
ResourceController
- Object
- ActionController::API
- BaseController
- ResourceController
- ResourceController
- Spree::Api::V3::Admin::PromotionActionsController
- Includes:
- SubclassedResource
- Defined in:
- app/controllers/spree/api/v3/admin/promotion_actions_controller.rb
Overview
CRUD for Spree::PromotionAction STI subclasses. Each action is
nested under a promotion; the create body picks the subclass via
type and the typed-preferences shape (preferences: {...}).
Constant Summary
Constants included from ScopedAuthorization
ScopedAuthorization::READ_ACTIONS
Constants inherited from BaseController
BaseController::RATE_LIMIT_RESPONSE
Constants included from Idempotent
Idempotent::IDEMPOTENCY_HEADER, Idempotent::IDEMPOTENCY_TTL, Idempotent::MAX_KEY_LENGTH, Idempotent::MUTATING_METHODS
Constants included from ErrorHandler
Constants included from JwtAuthentication
JwtAuthentication::JWT_AUDIENCE_ADMIN, JwtAuthentication::JWT_AUDIENCE_STORE, JwtAuthentication::JWT_ISSUER, JwtAuthentication::USER_TYPE_ADMIN, JwtAuthentication::USER_TYPE_CUSTOMER
Instance Method Summary collapse
-
#calculators ⇒ Object
Returns the calculator subclasses registered for the given action
type(e.g.?type=Spree::Promotion::Actions::CreateAdjustment). - #types ⇒ Object
Methods included from SubclassedResource
Methods inherited from ResourceController
#create, #destroy, #index, #show, #update
Methods included from Spree::Api::V3::ApiKeyAuthentication
#authenticate_api_key!, #authenticate_secret_key!
Methods included from JwtAuthentication
#authenticate_user, #require_authentication!
Instance Method Details
#calculators ⇒ Object
Returns the calculator subclasses registered for the given action
type (e.g. ?type=Spree::Promotion::Actions::CreateAdjustment).
Each entry includes the calculator's class name, label,
description, and preference schema so the SPA can render the
picker + nested fields without hardcoding the calculator list.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/spree/api/v3/admin/promotion_actions_controller.rb', line 27 def calculators :read, model_class klass = resolve_subclass(params[:type]) return render_unknown_type unless klass && klass.respond_to?(:calculators) data = klass.calculators.map do |calc| { type: calc.to_s, label: calc.respond_to?(:description) ? calc.description : calc.to_s.demodulize.titleize, preference_schema: calc.respond_to?(:serialized_preference_schema) ? calc.serialized_preference_schema : [] } end.sort_by { |entry| entry[:label].to_s } render json: { data: data } end |
#types ⇒ Object
16 17 18 19 20 |
# File 'app/controllers/spree/api/v3/admin/promotion_actions_controller.rb', line 16 def types :read, model_class render json: { data: model_class.subclasses_with_preference_schema } end |