Skip to content

Commit

Permalink
Refactor transaction scopes and add transaction_kind attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jan 18, 2024
1 parent 07aee27 commit 59156b6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/models/collective.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def sync_transactions
uuid: node['uuid'],
amount: node['amount']['value'],
net_amount: node['netAmount']['value'],
kind: node['type'],
transaction_type: node['type'],
transaction_kind: node['kind'],
currency: node['amount']['currency'],
account: node['type'] == 'DEBIT' ? node['toAccount']['slug'] : node['fromAccount']['slug'],
created_at: node['createdAt'],
Expand Down
4 changes: 2 additions & 2 deletions app/models/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Transaction < ApplicationRecord

counter_culture :collective, execute_after_commit: true

scope :donations, -> { where(kind: 'CREDIT') }
scope :expenses, -> { where(kind: 'DEBIT') }
scope :donations, -> { where(transaction_type: 'CREDIT') }
scope :expenses, -> { where(transaction_type: 'DEBIT') }
scope :host_fees, -> { where(description: "Host Fee")}
scope :not_host_fees, -> { where.not(description: "Host Fee")}
scope :created_after, ->(date) { where('created_at > ?', date) }
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20240118155013_add_kind_to_transactions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddKindToTransactions < ActiveRecord::Migration[7.1]
def change
add_column :transactions, :transaction_kind, :string
rename_column :transactions, :kind, :transaction_type
end
end
5 changes: 3 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 59156b6

Please sign in to comment.