processSplitTransactions handles the processing of multiple split transactions. It prepares each split transaction, persists them to the database, and creates queue copies. Parameters: - ctx context.Context: The context for the operation. - transactions []*model.Transaction: The split transactions
(ctx context.Context, transactions []*model.Transaction, originalTxnID, originalRef string)
| 1978 | // - []*model.Transaction: A slice of processed transactions ready for queueing. |
| 1979 | // - error: An error if any transaction processing fails. |
| 1980 | func (l *LedgerForge) processSplitTransactions(ctx context.Context, transactions []*model.Transaction, originalTxnID, originalRef string) ([]*model.Transaction, error) { |
| 1981 | queueTransactions := make([]*model.Transaction, len(transactions)) |
| 1982 | updateSplitTransactions(transactions, originalTxnID, originalRef) |
| 1983 | |
| 1984 | for i, splitTxn := range transactions { |
| 1985 | preparedSplitTxn, err := l.prepareTransactionForQueue(ctx, splitTxn) |
| 1986 | if err != nil { |
| 1987 | return nil, fmt.Errorf("failed to prepare split transaction %d: %w", i, err) |
| 1988 | } |
| 1989 | |
| 1990 | // Persist the original transaction |
| 1991 | persistedTxn, err := l.datasource.RecordTransaction(ctx, preparedSplitTxn) |
| 1992 | if err != nil { |
| 1993 | return nil, fmt.Errorf("failed to persist original transaction: %w", err) |
| 1994 | } |
| 1995 | |
| 1996 | queueTxn := createQueueCopy(persistedTxn, splitTxn.Reference) |
| 1997 | queueTransactions[i] = queueTxn |
| 1998 | } |
| 1999 | |
| 2000 | return queueTransactions, nil |
| 2001 | } |
| 2002 | |
| 2003 | // setTransactionStatus determines and sets the appropriate status for a transaction. |
| 2004 | // It evaluates the transaction's scheduled time and current status to set the correct status. |
no test coverage detected