handle add/remove homies in backend

This commit is contained in:
Bilal
2020-09-12 01:26:56 +03:00
parent 2a5ffac5b9
commit 013e4d144d
6 changed files with 42 additions and 20 deletions

View File

@@ -1,13 +1,13 @@
class Homie < ApplicationRecord
has_many :money_moves
belongs_to :chip
def self.cash(importance)
totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount)
totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount)
result = []
Homie.where(["importance > ?", importance]).map do |homie|
total = totals.fetch(homie.id, 0)
{ homie: homie, amount: total }
total = totals.fetch(homie.id, 0)
{ homie: homie, amount: total }
end
end
end