mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
feat: scope Mercury account uniqueness to mercury_item (#1032)
* feat: scope Mercury account uniqueness to mercury_item * feat: extend to all other providers * fix: add uniqueness test * fix: lint * fix: test * fix: coderabbit comment * fix: coderabbit comment * fix: coderabbit comment * fix: update * fix: lint * fix: update * fix: update
This commit is contained in:
@@ -15,6 +15,7 @@ class CoinbaseAccount < ApplicationRecord
|
||||
has_one :linked_account, through: :account_provider, source: :account
|
||||
|
||||
validates :name, :currency, presence: true
|
||||
validates :account_id, uniqueness: { scope: :coinbase_item_id, allow_nil: true }
|
||||
|
||||
# Helper to get account using account_providers system
|
||||
def current_account
|
||||
|
||||
@@ -16,6 +16,7 @@ class EnableBankingAccount < ApplicationRecord
|
||||
|
||||
validates :name, :currency, presence: true
|
||||
validates :uid, presence: true, uniqueness: { scope: :enable_banking_item_id }
|
||||
# account_id is not uniquely scoped: uid already enforces one-account-per-identifier per item
|
||||
|
||||
# Helper to get account using account_providers system
|
||||
def current_account
|
||||
|
||||
@@ -12,6 +12,7 @@ class IndexaCapitalAccount < ApplicationRecord
|
||||
has_one :linked_account, through: :account_provider, source: :account
|
||||
|
||||
validates :name, :currency, presence: true
|
||||
validates :indexa_capital_account_id, uniqueness: { scope: :indexa_capital_item_id, allow_nil: true }
|
||||
|
||||
# Scopes
|
||||
scope :with_linked, -> { joins(:account_provider) }
|
||||
|
||||
@@ -15,6 +15,7 @@ class LunchflowAccount < ApplicationRecord
|
||||
has_one :linked_account, through: :account_provider, source: :account
|
||||
|
||||
validates :name, :currency, presence: true
|
||||
validates :account_id, uniqueness: { scope: :lunchflow_item_id, allow_nil: true }
|
||||
|
||||
# Helper to get account using account_providers system
|
||||
def current_account
|
||||
|
||||
@@ -15,6 +15,7 @@ class MercuryAccount < ApplicationRecord
|
||||
has_one :linked_account, through: :account_provider, source: :account
|
||||
|
||||
validates :name, :currency, presence: true
|
||||
validates :account_id, uniqueness: { scope: :mercury_item_id }
|
||||
|
||||
# Helper to get account using account_providers system
|
||||
def current_account
|
||||
|
||||
@@ -19,6 +19,7 @@ class PlaidAccount < ApplicationRecord
|
||||
has_one :linked_account, through: :account_provider, source: :account
|
||||
|
||||
validates :name, :plaid_type, :currency, presence: true
|
||||
validates :plaid_id, uniqueness: { scope: :plaid_item_id }
|
||||
validate :has_balance
|
||||
|
||||
# Helper to get account using new system first, falling back to legacy
|
||||
|
||||
@@ -17,6 +17,8 @@ class SnaptradeAccount < ApplicationRecord
|
||||
has_one :linked_account, through: :account_provider, source: :account
|
||||
|
||||
validates :name, :currency, presence: true
|
||||
validates :account_id, uniqueness: { scope: :snaptrade_item_id, allow_nil: true }
|
||||
validates :snaptrade_account_id, uniqueness: { scope: :snaptrade_item_id, allow_nil: true }
|
||||
|
||||
# Enqueue cleanup job after destruction to avoid blocking transaction with API call
|
||||
after_destroy :enqueue_connection_cleanup
|
||||
|
||||
Reference in New Issue
Block a user