Skip to content

Commit

Permalink
more meaningful method name
Browse files Browse the repository at this point in the history
  • Loading branch information
akostadinov committed Sep 18, 2024
1 parent 53d0222 commit 48d986b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/controllers/admin/api/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ def index
def find
buyer_account = find_buyer_account
authorize! :read, buyer_account
respond_with(to_present(buyer_account))
respond_with(preload_to_present(buyer_account))
end

# Account Read
# GET /admin/api/accounts/{id}.xml
def show
authorize! :read, buyer_account

respond_with(to_present(buyer_account))
respond_with(preload_to_present(buyer_account))
end

# Account Update
# PUT /admin/api/accounts/{id}.xml
def update
authorize! :update, buyer_account

to_present(buyer_account)
preload_to_present(buyer_account)

buyer_account.vat_rate = params[:vat_rate].to_f if params[:vat_rate]
buyer_account.settings.attributes = billing_params
Expand Down Expand Up @@ -73,7 +73,7 @@ def change_plan
def approve
authorize! :approve, buyer_account

to_present buyer_account
preload_to_present buyer_account
buyer_account.approve

respond_with(buyer_account)
Expand All @@ -84,7 +84,7 @@ def approve
def reject
authorize! :reject, buyer_account

to_present buyer_account
preload_to_present buyer_account
buyer_account.reject

respond_with(buyer_account)
Expand All @@ -95,7 +95,7 @@ def reject
def make_pending
authorize! :update, buyer_account

to_present buyer_account
preload_to_present buyer_account
buyer_account.make_pending

respond_with(buyer_account)
Expand All @@ -115,7 +115,7 @@ def buyer_account
@buyer_account ||= buyer_accounts.find(params[:id])
end

def to_present(accounts)
def preload_to_present(accounts)
# ActiveRecord::Associations::Preloader.new(records: Array(accounts), associations: [:annotations, {bought_plans: %i[original]}]).call # Rails 7.x
ActiveRecord::Associations::Preloader.new.preload(Array(accounts), [:annotations, {bought_plans: %i[original]}])
accounts
Expand Down

0 comments on commit 48d986b

Please sign in to comment.