Add an API endpoint for EnterpriseFeesController#destroy

This commit is contained in:
Hugo Daniel
2018-11-09 17:27:25 +01:00
parent 5c208a68c6
commit 7b33712f7a
4 changed files with 25 additions and 2 deletions

View File

@@ -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 = '<a href="' + url + '" class="delete-resource icon_link icon-trash no-text" data-action="remove" data-confirm="' + t('are_you_sure') + '" url="' + url + '"></a>'
#var html = '<a href="'+url+'" class="delete-resource" data-confirm="Are you sure?"><img alt="Delete" src="/assets/admin/icons/delete.png" /> Delete</a>';
element.append html

View File

@@ -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

View File

@@ -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

View File

@@ -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