diff --git a/app/assets/javascripts/admin/enterprise_fees/directives/delete_resource.js.coffee b/app/assets/javascripts/admin/enterprise_fees/directives/delete_resource.js.coffee index c5936393db..ba37f0518f 100644 --- a/app/assets/javascripts/admin/enterprise_fees/directives/delete_resource.js.coffee +++ b/app/assets/javascripts/admin/enterprise_fees/directives/delete_resource.js.coffee @@ -1,7 +1,7 @@ angular.module('admin.enterpriseFees').directive 'spreeDeleteResource', -> (scope, element, attrs) -> if scope.enterprise_fee.id - url = '/admin/enterprise_fees/' + scope.enterprise_fee.id + url = '/api/enterprise_fees/' + scope.enterprise_fee.id html = '' #var html = 'Delete Delete'; element.append html diff --git a/app/controllers/api/enterprise_fees_controller.rb b/app/controllers/api/enterprise_fees_controller.rb new file mode 100644 index 0000000000..3d03b28515 --- /dev/null +++ b/app/controllers/api/enterprise_fees_controller.rb @@ -0,0 +1,21 @@ +module Api + class EnterpriseFeesController < BaseController + respond_to :json + + def destroy + authorize! :destroy, enterprise_fee + + if enterprise_fee.destroy + render text: I18n.t(:successfully_removed), status: 204 + else + render text: enterprise_fee.errors.full_messages.first, status: 403 + end + end + + private + + def enterprise_fee + @enterprise_fee ||= EnterpriseFee.find_by_id params[:id] + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 1196e950ee..4804e4cae2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,6 +111,8 @@ Openfoodnetwork::Application.routes.draw do resources :customers, only: [:index, :update] + resources :enterprise_fees, only: [:destroy] + post '/product_images/:product_id', to: 'product_images#update_product_image' end diff --git a/config/routes/admin.rb b/config/routes/admin.rb index c191322d74..1f55f8d154 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -35,7 +35,7 @@ Openfoodnetwork::Application.routes.draw do resources :enterprise_relationships resources :enterprise_roles - resources :enterprise_fees do + resources :enterprise_fees, except: :destroy do collection do get :for_order_cycle post :bulk_update, :as => :bulk_update