Class: Dscf::Marketplace::SupplierProductsController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- Dscf::Marketplace::SupplierProductsController
- Includes:
- Core::Common
- Defined in:
- app/controllers/dscf/marketplace/supplier_products_controller.rb
Instance Method Summary collapse
-
#approve ⇒ Object
Admin action to approve a supplier product (makes it active).
-
#create ⇒ Object
Override create so supplier submissions default to inactive (require approval).
- #my_products ⇒ Object
-
#reject ⇒ Object
Admin action to reject a supplier product (makes it inactive).
Methods inherited from ApplicationController
#bypass_permissions_for_demo?, #pundit_user
Instance Method Details
#approve ⇒ Object
Admin action to approve a supplier product (makes it active)
47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/dscf/marketplace/supplier_products_controller.rb', line 47 def approve set_object @obj, :approve? if @obj.update(status: :active) render_success("supplier_products.success.approve", data: @obj) else render_error("supplier_products.errors.approve", errors: @obj.errors., status: :unprocessable_entity) end end |
#create ⇒ Object
Override create so supplier submissions default to inactive (require approval)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/dscf/marketplace/supplier_products_controller.rb', line 20 def create @clazz.new, :create? obj = @clazz.new(model_params) # Ensure newly created supplier products are inactive until approved by platform admin obj.status = :inactive ActiveRecord::Base.transaction do if obj.save @obj = obj after_save_hook(obj) if respond_to?(:after_save_hook, true) obj = @clazz.includes(eager_loaded_associations).find(obj.id) if eager_loaded_associations.present? @obj = obj includes = serializer_includes_for_action(:create) = {} [:include] = includes if includes.present? render_success(data: obj, serializer_options: , status: :created) else render_error(errors: obj.errors.[0], status: :unprocessable_entity) end end end |
#my_products ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/dscf/marketplace/supplier_products_controller.rb', line 6 def my_products @clazz.new, :my_products? service = MyResourceService.new(current_user) products = service.my_products(params) = { include: default_serializer_includes[:index] || [], meta: {resource_type: "my_products"} } render_success("supplier_products.success.index", data: products, serializer_options: ) end |
#reject ⇒ Object
Admin action to reject a supplier product (makes it inactive)
59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/dscf/marketplace/supplier_products_controller.rb', line 59 def reject set_object @obj, :approve? if @obj.update(status: :inactive) render_success("supplier_products.success.reject", data: @obj) else render_error("supplier_products.errors.reject", errors: @obj.errors., status: :unprocessable_entity) end end |