2020-07-25 16:18:59 +02:00
|
|
|
class Api::V1::User::FinancialTransactionsController < Api::V1::BaseController
|
|
|
|
include Concerns::CollectionScope
|
|
|
|
|
|
|
|
before_action ->{ doorkeeper_authorize! 'finance:user' }
|
|
|
|
before_action :require_ordergroup
|
2021-02-18 12:37:22 +01:00
|
|
|
before_action :require_minimum_balance, only: [:create]
|
|
|
|
before_action -> { require_config_enabled :use_self_service }, only: [:create]
|
2020-07-25 16:18:59 +02:00
|
|
|
|
|
|
|
def index
|
|
|
|
render_collection search_scope
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
render json: scope.find(params.require(:id))
|
|
|
|
end
|
|
|
|
|
2021-02-18 12:37:22 +01:00
|
|
|
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
|
|
|
|
|
2020-07-25 16:18:59 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def scope
|
2021-02-08 01:09:01 +01:00
|
|
|
current_ordergroup.financial_transactions.includes(:user, :financial_transaction_type)
|
2020-07-25 16:18:59 +02:00
|
|
|
end
|
|
|
|
|
2021-02-18 12:37:22 +01:00
|
|
|
def create_params
|
|
|
|
params.require(:financial_transaction).permit(:amount, :financial_transaction_type_id, :note)
|
|
|
|
end
|
|
|
|
|
2020-07-25 16:18:59 +02:00
|
|
|
end
|