DoubleEntryLedger.Stores.TransactionStoreHelper (double_entry_ledger v0.2.0)
View SourceProvides helper functions for building Ecto.Multi operations related to transactions in the double-entry ledger system.
This module focuses on constructing changesets and multi-step operations for creating and updating transactions, ensuring that all necessary validations and business rules are applied.
Key Functionality
- Transaction Creation: Build Ecto.Multi operations for creating new transactions
- Transaction Updates: Build Ecto.Multi operations for updating existing transactions
- Error Handling: Manage potential errors such as
Ecto.StaleEntryErrorduring concurrent updates - Status Transitions: Handle transaction status changes with appropriate validations
Usage Examples
Summary
Functions
Builds an Ecto.Multi to create a new transaction. This is used as a building block for more complex
operations.
Builds an Ecto.Multi to update a transaction. This is used as a building block for more complex
operations.
Functions
@spec build_create(Ecto.Multi.t(), atom(), map(), Ecto.Repo.t()) :: Ecto.Multi.t()
Builds an Ecto.Multi to create a new transaction. This is used as a building block for more complex
operations.
It also handles the Ecto.StaleEntryError exception that can be raised when accounts associated
with the transaction have been updated in the meantime. In this case it returns an error tuple
which is then converted to an Ecto.Multi.failure() to be handled by the caller.
Parameters
multi- The existingEcto.Multistruct.step- An atom representing the name of the operation.transaction- A map of transaction attributes.repo- The repository module (defaults toRepo).
Returns
- An
Ecto.Multistruct with the create operation added.
@spec build_update( Ecto.Multi.t(), atom(), DoubleEntryLedger.Transaction.t() | atom(), map(), Ecto.Repo.t() ) :: Ecto.Multi.t()
Builds an Ecto.Multi to update a transaction. This is used as a building block for more complex
operations.
It also handles the Ecto.StaleEntryError exception that can be raised when accounts associated
with the transaction have been updated in the meantime. In this case it returns an error tuple
which is then converted to an Ecto.Multi.failure() to be handled by the caller.
Parameters
multi- The existingEcto.Multistruct.step- An atom representing the name of the operation.transaction- TheTransactionstruct to be updated.attrs- A map of attributes for the update.repo- The repository module (defaults toRepo).
Returns
- An
Ecto.Multistruct with the update operation added.