foodsoft/app/controllers/api/v1/user/financial_transactions_controller.rb
viehlieb e37ad34901
Some checks failed
continuous-integration/drone/push Build is failing
mv lib to app/lib use :zeitwerk
2022-10-18 17:23:18 +02:00

32 lines
985 B
Ruby

class Api::V1::User::FinancialTransactionsController < Api::V1::BaseController
include CollectionScope
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
end
def show
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