28 lines
727 B
Ruby
28 lines
727 B
Ruby
class LndhubUser < LndhubBase
|
|
self.table_name = "users"
|
|
self.inheritance_column = :_type_disabled
|
|
|
|
has_many :accounts, class_name: "LndhubAccount",
|
|
foreign_key: "user_id"
|
|
|
|
belongs_to :user, class_name: "User",
|
|
primary_key: "lndhub_username",
|
|
foreign_key: "login"
|
|
|
|
def balance
|
|
accounts.current.first.ledgers.sum("account_ledgers.amount").to_i.abs
|
|
end
|
|
|
|
def sum_outgoing
|
|
accounts.outgoing.first.ledgers.sum("account_ledgers.amount").to_i.abs
|
|
end
|
|
|
|
def sum_incoming
|
|
accounts.incoming.first.ledgers.sum("account_ledgers.amount").to_i.abs
|
|
end
|
|
|
|
def sum_fees
|
|
accounts.fees.first.ledgers.sum("account_ledgers.amount").to_i.abs
|
|
end
|
|
end
|