mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Prevent account deletions when account is linked to a Plaid Item (#2218)
* Prevent account deletions when account is linked to a Plaid Item * Only guard deletions in UI and controller, not at model level
This commit is contained in:
parent
628d266980
commit
a67f36bf64
7 changed files with 39 additions and 25 deletions
|
@ -15,13 +15,20 @@ class PlaidAccount < ApplicationRecord
|
|||
|
||||
class << self
|
||||
def find_or_create_from_plaid_data!(plaid_data, family)
|
||||
find_or_create_by!(plaid_id: plaid_data.account_id) do |a|
|
||||
a.account = family.accounts.new(
|
||||
name: plaid_data.name,
|
||||
balance: plaid_data.balances.current || plaid_data.balances.available,
|
||||
currency: plaid_data.balances.iso_currency_code,
|
||||
accountable: TYPE_MAPPING[plaid_data.type].new
|
||||
)
|
||||
PlaidAccount.transaction do
|
||||
plaid_account = find_or_create_by!(plaid_id: plaid_data.account_id)
|
||||
|
||||
internal_account = family.accounts.find_or_initialize_by(plaid_account_id: plaid_account.id)
|
||||
|
||||
internal_account.name = plaid_data.name
|
||||
internal_account.balance = plaid_data.balances.current || plaid_data.balances.available
|
||||
internal_account.currency = plaid_data.balances.iso_currency_code
|
||||
internal_account.accountable = TYPE_MAPPING[plaid_data.type].new
|
||||
|
||||
internal_account.save!
|
||||
plaid_account.save!
|
||||
|
||||
plaid_account
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue