Add API v1 financial_transactions POST endpoint

In a first step we allow members to create financial transactions
for their own ordergroup.
This commit is contained in:
Patrick Gansterer 2021-02-18 12:37:22 +01:00
parent 9d68abd908
commit e6061e6760
6 changed files with 211 additions and 18 deletions

View file

@ -3,6 +3,8 @@ class Api::V1::User::FinancialTransactionsController < Api::V1::BaseController
before_action ->{ doorkeeper_authorize! 'finance:user' }
before_action :require_ordergroup
before_action :require_minimum_balance, only: [:create]
before_action -> { require_config_enabled :use_self_service }, only: [:create]
def index
render_collection search_scope
@ -12,10 +14,20 @@ class Api::V1::User::FinancialTransactionsController < Api::V1::BaseController
render json: scope.find(params.require(:id))
end
def create
transaction_type = FinancialTransactionType.find(create_params[:financial_transaction_type_id])
ft = current_ordergroup.add_financial_transaction!(create_params[:amount], create_params[:note], current_user, transaction_type)
render json: ft
end
private
def scope
current_ordergroup.financial_transactions.includes(:user, :financial_transaction_type)
end
def create_params
params.require(:financial_transaction).permit(:amount, :financial_transaction_type_id, :note)
end
end

View file

@ -90,6 +90,7 @@ class Ordergroup < Group
if t.amount < 0 && self.account_balance < 0 && self.account_balance - t.amount >= 0
Resque.enqueue(UserNotifier, FoodsoftConfig.scope, 'negative_balance', self.id, t.id)
end
t
end
end