update transactions query to include peer
This commit is contained in:
parent
65e6278b67
commit
2d753146f0
1 changed files with 13 additions and 8 deletions
|
@ -2,22 +2,25 @@ class TransactionsQuery
|
||||||
def initialize user
|
def initialize user
|
||||||
@user = user
|
@user = user
|
||||||
@transactions = Arel::Table.new(:transactions)
|
@transactions = Arel::Table.new(:transactions)
|
||||||
|
@perspectived = Arel::Table.new(:perspectived_transactions)
|
||||||
|
@peers = Arel::Table.new(:users).alias('peers')
|
||||||
end
|
end
|
||||||
|
|
||||||
def arel
|
def arel
|
||||||
Arel::SelectManager.new(ActiveRecord::Base)
|
Arel::SelectManager.new(ActiveRecord::Base)
|
||||||
.from(transactions)
|
.from(transactions)
|
||||||
|
.join(@peers).on(@peers[:id].eq(@perspectived[:peer_id]))
|
||||||
.project(
|
.project(
|
||||||
@transactions[:amount],
|
@perspectived[:amount],
|
||||||
@transactions[:date],
|
@perspectived[:date],
|
||||||
@transactions[:peer_id],
|
@peers[:name].as('peer'),
|
||||||
@transactions[:issuer_id],
|
@perspectived[:issuer_id],
|
||||||
@transactions[:message]
|
@perspectived[:message]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def transactions
|
def transactions
|
||||||
Arel::Nodes::UnionAll.new(outgoing, incoming)
|
Arel::Nodes::TableAlias.new(incoming.union(outgoing), @perspectived.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def outgoing
|
def outgoing
|
||||||
|
@ -28,7 +31,8 @@ class TransactionsQuery
|
||||||
@transactions[:creditor_id].as('peer_id'),
|
@transactions[:creditor_id].as('peer_id'),
|
||||||
@transactions[:created_at].as('date'),
|
@transactions[:created_at].as('date'),
|
||||||
@transactions[:issuer_id],
|
@transactions[:issuer_id],
|
||||||
@transactions[:issuer_type]
|
@transactions[:issuer_type],
|
||||||
|
@transactions[:message]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,7 +45,8 @@ class TransactionsQuery
|
||||||
@transactions[:debtor_id].as('peer_id'),
|
@transactions[:debtor_id].as('peer_id'),
|
||||||
@transactions[:created_at].as('date'),
|
@transactions[:created_at].as('date'),
|
||||||
@transactions[:issuer_id],
|
@transactions[:issuer_id],
|
||||||
@transactions[:issuer_type]
|
@transactions[:issuer_type],
|
||||||
|
@transactions[:message]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue