DoubleEntryLedger.Stores.JournalEventStoreHelper (double_entry_ledger v0.4.0)
View SourceHelper functions for journal event queries in the Double Entry Ledger system.
This module provides reusable utilities for working with journal events, focusing on common operations like retrieving related journal events by source identifiers, finding transactions and accounts associated with journal events, and building queries for audit trail access.
Key Functionality
- Journal Event Lookup: Find journal events by action and source identifiers
- Command Relationships: Look up related journal events for commands
- Transaction Linking: Find transactions and accounts associated with journal events
- Query Building: Compose queries for journal events by account or transaction
Implementation Notes
This module is primarily used internally by JournalEventStore and CommandWorker modules to share common functionality and reduce code duplication.
Summary
Functions
Gets the account associated with a create account command's journal event.
Retrieves a journal event by its action and source identifiers with preloaded associations.
Functions
@spec all_processed_events_for_account_id(Ecto.UUID.t()) :: Ecto.Query.t()
@spec base_account_query(Ecto.UUID.t()) :: Ecto.Query.t()
@spec base_transaction_query(Ecto.UUID.t()) :: Ecto.Query.t()
@spec get_create_account_event_account(DoubleEntryLedger.Command.t()) :: {:ok, {DoubleEntryLedger.Account.t(), DoubleEntryLedger.JournalEvent.t()}} | {:error | :pending_error, String.t(), DoubleEntryLedger.JournalEvent.t() | nil}
Gets the account associated with a create account command's journal event.
This function finds the original create account journal event corresponding to an update command and returns its associated account. Used primarily when processing account update commands to locate the original account to modify.
Parameters
command- A Command struct containing source, source_idempk, and instance_id
Returns
{:ok, {Account.t(), JournalEvent.t()}}- The account and create journal event if found- Raises
UpdateCommandErrorif the create journal event doesn't exist or isn't processed
@spec get_event_by(atom(), String.t(), String.t(), Ecto.UUID.t()) :: DoubleEntryLedger.JournalEvent.t() | nil
Retrieves a journal event by its action and source identifiers with preloaded associations.
This function looks up a journal event using its action, source system identifier, source-specific identifier, and instance ID. The returned journal event includes a preloaded account association.
Parameters
action: The command action atom (e.g.,:create_transaction,:create_account)source: The source system identifier (e.g., "accounting_system", "api")source_idempk: The source-specific identifier (e.g., "invoice_123", "tx_456")instance_id: The instance UUID that scopes the lookup
Returns
JournalEvent.t() | nil: The found journal event with preloaded account, or nil if not found
@spec transaction_events_for_account_query(Ecto.UUID.t()) :: Ecto.Query.t()