mirror of
https://github.com/we-promise/sure.git
synced 2026-04-17 02:54:10 +00:00
- Add SimplefinItem model with sync capabilities and encryption - Add SimplefinAccount model for account data mapping - Implement Provider::Simplefin API client with token exchange - Add SimpleFin protocol support with proper error handling - Include sync jobs, importers, and processors for data flow - Add family SimpleFin connectivity mixin
34 lines
1017 B
Ruby
34 lines
1017 B
Ruby
class SimplefinItem::Syncer
|
|
attr_reader :simplefin_item
|
|
|
|
def initialize(simplefin_item)
|
|
@simplefin_item = simplefin_item
|
|
end
|
|
|
|
def perform_sync(sync)
|
|
# Loads item metadata, accounts, transactions from SimpleFin API
|
|
simplefin_item.import_latest_simplefin_data
|
|
|
|
# Check if this is the first sync and we have new accounts to set up
|
|
if simplefin_item.accounts.empty? && simplefin_item.simplefin_accounts.any?
|
|
# Mark as pending account setup so user can choose account types
|
|
simplefin_item.update!(pending_account_setup: true)
|
|
return
|
|
end
|
|
|
|
# Processes the raw SimpleFin data and updates internal domain objects
|
|
simplefin_item.process_accounts
|
|
|
|
# All data is synced, so we can now run an account sync to calculate historical balances and more
|
|
simplefin_item.schedule_account_syncs(
|
|
parent_sync: sync,
|
|
window_start_date: sync.window_start_date,
|
|
window_end_date: sync.window_end_date
|
|
)
|
|
end
|
|
|
|
def perform_post_sync
|
|
# no-op
|
|
end
|
|
end
|