mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-08 15:05:22 +02:00
Add initial processing
This commit is contained in:
parent
fa6e5ff595
commit
d3a0e98b02
4 changed files with 31 additions and 13 deletions
|
@ -73,6 +73,12 @@ class Account < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_name(name)
|
||||||
|
if enrichable?(:name)
|
||||||
|
self.name = name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def institution_domain
|
def institution_domain
|
||||||
url_string = plaid_account&.plaid_item&.institution_url
|
url_string = plaid_account&.plaid_item&.institution_url
|
||||||
return nil unless url_string.present?
|
return nil unless url_string.present?
|
||||||
|
|
22
app/models/plaid_account/processor.rb
Normal file
22
app/models/plaid_account/processor.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
class PlaidAccount::Processor
|
||||||
|
attr_reader :plaid_account
|
||||||
|
|
||||||
|
def initialize(plaid_account)
|
||||||
|
@plaid_account = plaid_account
|
||||||
|
end
|
||||||
|
|
||||||
|
def process
|
||||||
|
PlaidAccount.transaction do
|
||||||
|
account = family.accounts.find_or_initialize_by(
|
||||||
|
plaid_account_id: plaid_account.id
|
||||||
|
)
|
||||||
|
|
||||||
|
account.set_name(plaid_account.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def family
|
||||||
|
plaid_account.plaid_item.family
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,8 +0,0 @@
|
||||||
class PlaidItem::Processor
|
|
||||||
def initialize(plaid_item)
|
|
||||||
@plaid_item = plaid_item
|
|
||||||
end
|
|
||||||
|
|
||||||
def process_data
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -10,7 +10,9 @@ class PlaidItem::Syncer
|
||||||
fetch_and_import_item_data
|
fetch_and_import_item_data
|
||||||
|
|
||||||
# Processes the raw Plaid data and updates internal domain objects
|
# Processes the raw Plaid data and updates internal domain objects
|
||||||
process_item_data
|
plaid_item.plaid_accounts.each do |plaid_account|
|
||||||
|
PlaidAccount::Processor.new(plaid_account).process
|
||||||
|
end
|
||||||
|
|
||||||
# All data is synced, so we can now run an account sync to calculate historical balances and more
|
# All data is synced, so we can now run an account sync to calculate historical balances and more
|
||||||
plaid_item.reload.accounts.each do |account|
|
plaid_item.reload.accounts.each do |account|
|
||||||
|
@ -35,10 +37,6 @@ class PlaidItem::Syncer
|
||||||
PlaidItem::Importer.new(plaid_item, plaid_provider: plaid_provider).import
|
PlaidItem::Importer.new(plaid_item, plaid_provider: plaid_provider).import
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_item_data
|
|
||||||
PlaidItem::Processor.new(plaid_item).process_data
|
|
||||||
end
|
|
||||||
|
|
||||||
def safe_fetch_plaid_data(method)
|
def safe_fetch_plaid_data(method)
|
||||||
begin
|
begin
|
||||||
plaid.send(method, plaid_item)
|
plaid.send(method, plaid_item)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue