Skip to content

Commit 9a1db36

Browse files
committed
Refactor transaction retrieval to use JSON query for OrderId in funds controller
1 parent d1ecdf1 commit 9a1db36

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

app/controllers/funds_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ def donate
3030
@allocation = @fund.allocations.order('created_at DESC').first
3131

3232
if params[:OrderId].present?
33-
@transaction = Transaction.find_by_legacy_id(params[:OrderId])
33+
id = params[:OrderId]
34+
35+
@transaction = Transaction.donations.where("transactions.order->>'legacyId' = ?", id.to_s)
3436
if @transaction.nil?
3537
@fund.sync_transactions
36-
@transaction = Transaction.find_by_legacy_id(params[:OrderId])
38+
@transaction = Transaction.donations.where("transactions.order->>'legacyId' = ?", id.to_s)
3739
raise ActiveRecord::RecordNotFound unless @transaction
3840
end
3941
end

app/models/transaction.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ class Transaction < ApplicationRecord
1313
scope :created_before, ->(date) { where('transactions.created_at < ?', date) }
1414
scope :between, ->(start_date, end_date) { where('transactions.created_at > ?', start_date).where('transactions.created_at < ?', end_date) }
1515

16-
def self.find_by_legacy_id(id)
17-
Transaction.where("transactions.order->>'legacyId' = ?", id.to_s).first
18-
end
19-
2016
def html_url
2117
return unless order.present?
2218

0 commit comments

Comments
 (0)