foodsoft/app/controllers/api/v1/user/financial_transactions_controller.rb
Philipp Rothmann fb2b4d8a8a chore: rubocop
chore: fix api test conventions

chore: rubocop -A spec/

chore: more rubocop -A

fix failing test

rubocop fixes

removes helper methods that are in my opinion dead code

more rubocop fixes

rubocop -a --auto-gen-config
2023-06-09 17:35:05 +02:00

33 lines
1 KiB
Ruby

class Api::V1::User::FinancialTransactionsController < Api::V1::BaseController
include Concerns::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