add withdrawl and deposit to FiatBalance and Balance

This commit is contained in:
João Geonizeli
2021-08-15 01:02:39 -03:00
parent c1129b9953
commit 4b1341677f
11 changed files with 170 additions and 30 deletions

View File

@@ -25,5 +25,13 @@ class Balance < ApplicationRecord
belongs_to :user
belongs_to :currency
validates :amount, presence: true
validates :amount, presence: true, numericality: { greater_than_or_equal_to: 0 }
def withdrawal!(value)
update!(amount: amount - value)
end
def deposit!(value)
update!(amount: amount + value)
end
end