mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 12:05:19 +02:00
* Adds basic validations for required fields Also deletes a few extraneous .keep files Does not add the family_id required field for user, since that breaks the basic test setup * Restore keep files to this branch * Remove Credit model and validate models behind ids * Restore concerns .keep
16 lines
466 B
Ruby
16 lines
466 B
Ruby
class ExchangeRate < ApplicationRecord
|
|
validates :base_currency, :converted_currency, presence: true
|
|
|
|
def self.convert(from, to, amount)
|
|
return amount unless EXCHANGE_RATE_ENABLED
|
|
|
|
rate = ExchangeRate.find_by(base_currency: from, converted_currency: to)
|
|
|
|
# TODO: Handle the case where the rate is not found
|
|
if rate.nil?
|
|
amount # Silently handle the error by returning the original amount
|
|
else
|
|
amount * rate.rate
|
|
end
|
|
end
|
|
end
|