Class: Spree::Api::V3::Admin::Customers::StoreCreditsController
- Inherits:
-
ResourceController
- Object
- ActionController::API
- BaseController
- ResourceController
- ResourceController
- Spree::Api::V3::Admin::Customers::StoreCreditsController
- Defined in:
- app/controllers/spree/api/v3/admin/customers/store_credits_controller.rb
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
-
#create ⇒ Object
POST /api/v3/admin/customers/:customer_id/store_credits.
-
#destroy ⇒ Object
DELETE /api/v3/admin/customers/:customer_id/store_credits/:id.
-
#update ⇒ Object
PATCH /api/v3/admin/customers/:customer_id/store_credits/:id.
Methods inherited from ResourceController
Methods included from Spree::Api::V3::ApiKeyAuthentication
#authenticate_api_key!, #authenticate_secret_key!
Methods included from JwtAuthentication
#authenticate_user, #require_authentication!
Instance Method Details
#create ⇒ Object
POST /api/v3/admin/customers/:customer_id/store_credits
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/spree/api/v3/admin/customers/store_credits_controller.rb', line 10 def create @resource = @parent.store_credits.new(create_attrs) @resource.created_by = try_spree_current_user @resource.store ||= current_store @resource.category ||= Spree::StoreCreditCategory.first (@resource, :create) if @resource.save render json: serialize_resource(@resource), status: :created else render_validation_error(@resource.errors) end end |
#destroy ⇒ Object
DELETE /api/v3/admin/customers/:customer_id/store_credits/:id
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/spree/api/v3/admin/customers/store_credits_controller.rb', line 45 def destroy (@resource) if @resource.amount_used.positive? render_error( code: 'store_credit_in_use', message: 'Cannot delete a store credit that has already been used', status: :unprocessable_content ) return end @resource.destroy head :no_content end |
#update ⇒ Object
PATCH /api/v3/admin/customers/:customer_id/store_credits/:id
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/spree/api/v3/admin/customers/store_credits_controller.rb', line 25 def update (@resource) if @resource.amount_used.positive? && update_attrs.key?(:amount) render_error( code: 'store_credit_in_use', message: 'Cannot change amount on a store credit that has already been used', status: :unprocessable_content ) return end if @resource.update(update_attrs) render json: serialize_resource(@resource.reload) else render_validation_error(@resource.errors) end end |