Compare commits
1 Commits
81a03ca2c1
...
73e7c784a3
| Author | SHA1 | Date | |
|---|---|---|---|
| 73e7c784a3 |
@@ -333,8 +333,17 @@ func (s TransactionRecurringImpl) Delete(user *types.User, id string) error {
|
||||
func (s TransactionRecurringImpl) GenerateTransactions(user *types.User) error {
|
||||
now := s.clock.Now()
|
||||
|
||||
tx, err := s.db.Beginx()
|
||||
err = db.TransformAndLogDbError("transactionRecurring GenerateTransactions", nil, err)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
_ = tx.Rollback()
|
||||
}()
|
||||
|
||||
recurringTransactions := make([]*types.TransactionRecurring, 0)
|
||||
err := s.db.Select(&recurringTransactions, `
|
||||
err = tx.Select(&recurringTransactions, `
|
||||
SELECT * FROM transaction_recurring WHERE user_id = ? AND next_execution <= ?`,
|
||||
user.Id, now)
|
||||
err = db.TransformAndLogDbError("transactionRecurring GenerateTransactions", nil, err)
|
||||
@@ -358,7 +367,7 @@ func (s TransactionRecurringImpl) GenerateTransactions(user *types.User) error {
|
||||
}
|
||||
|
||||
nextExecution := transactionRecurring.NextExecution.AddDate(0, int(transactionRecurring.IntervalMonths), 0)
|
||||
r, err := s.db.Exec(`UPDATE transaction_recurring SET next_execution = ? WHERE id = ? AND user_id = ?`,
|
||||
r, err := tx.Exec(`UPDATE transaction_recurring SET next_execution = ? WHERE id = ? AND user_id = ?`,
|
||||
nextExecution, transactionRecurring.Id, user.Id)
|
||||
err = db.TransformAndLogDbError("transactionRecurring GenerateTransactions", r, err)
|
||||
if err != nil {
|
||||
@@ -366,6 +375,11 @@ func (s TransactionRecurringImpl) GenerateTransactions(user *types.User) error {
|
||||
}
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
err = db.TransformAndLogDbError("transactionRecurring GenerateTransactions", nil, err)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user