mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 03:24:09 +00:00
* Move provider config to family * Update schema.rb * Add provier generator * Add table creation also * FIX generator namespace * Add support for global providers also * Remove over-engineered stuff * FIX parser * FIX linter * Some generator fixes * Update generator with fixes * Update item_model.rb.tt * Add missing linkable concern * Add missing routes * Update adapter.rb.tt * Update connectable_concern.rb.tt * Update unlinking_concern.rb.tt * Update family_generator.rb * Update family_generator.rb * Delete .claude/settings.local.json Signed-off-by: soky srm <sokysrm@gmail.com> * Move docs under API related folder * Rename Rails generator doc * Light edits to LLM generated doc * Small Lunch Flow config panel regressions. --------- Signed-off-by: soky srm <sokysrm@gmail.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
53 lines
1.7 KiB
Plaintext
53 lines
1.7 KiB
Plaintext
class <%= class_name %>Account < ApplicationRecord
|
|
include CurrencyNormalizable
|
|
|
|
belongs_to :<%= file_name %>_item
|
|
|
|
# Association through account_providers for linking to internal accounts
|
|
has_one :account_provider, as: :provider, dependent: :destroy
|
|
has_one :account, through: :account_provider, source: :account
|
|
has_one :linked_account, through: :account_provider, source: :account
|
|
|
|
validates :name, :currency, presence: true
|
|
|
|
# Helper to get account using account_providers system
|
|
def current_account
|
|
account
|
|
end
|
|
|
|
def upsert_<%= file_name %>_snapshot!(account_snapshot)
|
|
# Convert to symbol keys or handle both string and symbol keys
|
|
snapshot = account_snapshot.with_indifferent_access
|
|
|
|
# Map <%= class_name %> field names to our field names
|
|
# TODO: Customize this mapping based on your provider's API response
|
|
update!(
|
|
current_balance: snapshot[:balance] || snapshot[:current_balance],
|
|
currency: parse_currency(snapshot[:currency]) || "USD",
|
|
name: snapshot[:name],
|
|
account_id: snapshot[:id]&.to_s,
|
|
account_status: snapshot[:status],
|
|
provider: snapshot[:provider],
|
|
institution_metadata: {
|
|
name: snapshot[:institution_name],
|
|
logo: snapshot[:institution_logo]
|
|
}.compact,
|
|
raw_payload: account_snapshot
|
|
)
|
|
end
|
|
|
|
def upsert_<%= file_name %>_transactions_snapshot!(transactions_snapshot)
|
|
assign_attributes(
|
|
raw_transactions_payload: transactions_snapshot
|
|
)
|
|
|
|
save!
|
|
end
|
|
|
|
private
|
|
|
|
def log_invalid_currency(currency_value)
|
|
Rails.logger.warn("Invalid currency code '#{currency_value}' for <%= class_name %> account #{id}, defaulting to USD")
|
|
end
|
|
end
|