Current sync

This commit is contained in:
Senad Uka
2020-05-18 11:35:34 +02:00
parent 41b5ebb5d7
commit fb0a6c7dfd
11 changed files with 170 additions and 90 deletions

View File

@@ -1,4 +1,25 @@
class MoneyMove < ApplicationRecord
belongs_to :from_homie, class_name: 'Homie'
belongs_to :to_homie, class_name: 'Homie'
belongs_to :homie
def create_move(params)
common_params = { description: params[:description] }
move_from = MoneyMove.new(
common_params + {
homie_id: params[:from_homie_id],
amount: -BigDecimal.new(params[:amount])
}
)
move_to = MoneyMove.new(
common_params + {
homie_id: params[:from_homie_id],
amount: BigDecimal.new(params[:amount])
}
)
MoneyMove.transaction do
move_from.save!
move_to.save!
end
end
end