DoubleEntryLedger.Workers.CommandWorker.UpdateAccountCommandMapNoSaveOnError (double_entry_ledger v0.4.0)
View SourceProcesses AccountCommandMap structures for atomic update of events and their associated accounts.
This module handles the update of accounts based on validated AccountCommandMap data within the Double Entry Ledger system. Unlike standard update event processors, this variant does not persist error states to the database, instead returning changesets with error details for client handling.
Key Features
- Account Processing: Handles update of accounts based on the event map's action
- Atomic Operations: Ensures all event and account changes are performed in a single database transaction
- Error Handling: Maps validation and dependency errors to appropriate changesets without persistence
- Optimistic Concurrency Control: Integrates with OCC patterns for safe concurrent processing
- Dependency Resolution: Locates original create events and their associated accounts
Processing Flow
- Command Creation: Creates an Command record from the AccountCommandMap for audit purposes
- Dependency Resolution: Locates the original create account event and its account
- Account Update: Updates the account using the payload data
- Command Completion: Marks the event as processed upon successful account update
- Linking: Creates a link between the event and the updated account for traceability
Error Handling
The module provides comprehensive error handling:
- Command validation errors are mapped back to AccountCommandMap changesets
- Account validation errors are propagated to the event map payload
- Dependency errors (missing create events) are handled gracefully
- All errors are returned as changesets without database persistence
- Database transaction ensures atomicity (all-or-nothing)
Supported Actions
Currently supports:
:update_account- Updates an existing account from AccountCommandMap payload
Usage
This module is designed for scenarios where error persistence should be managed externally, allowing clients to handle validation errors and retry logic according to their specific requirements.
Summary
Functions
Processes an AccountCommandMap to update an existing account in the ledger system.
Functions
@spec process(DoubleEntryLedger.Command.AccountCommandMap.t()) :: DoubleEntryLedger.Workers.CommandWorker.AccountCommandMapResponseHandler.response()
Processes an AccountCommandMap to update an existing account in the ledger system.
This function orchestrates the update of both an Command record (for audit trail) and an Account record within a single database transaction. It first locates the original create account event and its associated account, then applies the updates from the event map's payload.
Parameters
command_map- AccountCommandMap struct containing validated account update data. Must have:update_accountaction.
Returns
{:ok, Account.t(), Command.t()}- Success tuple containing the updated Account and Command{:error, Changeset.t(AccountCommandMap.t())}- AccountCommandMap changeset with validation errors{:error, String.t()}- String error message for unexpected failures
Transaction Steps
- Creates Command record from AccountCommandMap
- Locates original create account event and its account
- Updates Account record with payload data
- Marks Command as processed
- Creates Command-Account link for traceability
Error Scenarios
- Command validation errors → AccountCommandMap changeset with event-level errors
- Missing create account event → AccountCommandMap changeset with dependency error
- Account validation errors → AccountCommandMap changeset with payload-level errors
- Other failures → String error message with details