feat(transaction-recurring): #100 replace active with next-execution
This commit was merged in pull request #133.
This commit is contained in:
@@ -76,9 +76,9 @@ func (s TransactionRecurringImpl) Add(
|
||||
|
||||
r, err := tx.NamedExec(`
|
||||
INSERT INTO "transaction_recurring" (id, user_id, interval_months,
|
||||
active, party, description, account_id, treasure_chest_id, value, created_at, created_by)
|
||||
next_execution, party, description, account_id, treasure_chest_id, value, created_at, created_by)
|
||||
VALUES (:id, :user_id, :interval_months,
|
||||
:active, :party, :description, :account_id, :treasure_chest_id, :value, :created_at, :created_by)`,
|
||||
:next_execution, :party, :description, :account_id, :treasure_chest_id, :value, :created_at, :created_by)`,
|
||||
transactionRecurring)
|
||||
err = db.TransformAndLogDbError("transactionRecurring Insert", r, err)
|
||||
if err != nil {
|
||||
@@ -135,7 +135,7 @@ func (s TransactionRecurringImpl) Update(
|
||||
UPDATE transaction_recurring
|
||||
SET
|
||||
interval_months = :interval_months,
|
||||
active = :active,
|
||||
next_execution = :next_execution,
|
||||
party = :party,
|
||||
description = :description,
|
||||
account_id = :account_id,
|
||||
@@ -444,15 +444,24 @@ func (s TransactionRecurringImpl) validateAndEnrichTransactionRecurring(
|
||||
log.Error("transactionRecurring validate: %v", err)
|
||||
return nil, fmt.Errorf("intervalMonths needs to be greater than 0: %w", ErrBadRequest)
|
||||
}
|
||||
active := input.Active == "on"
|
||||
var nextExecution *time.Time = nil
|
||||
if input.NextExecution != "" {
|
||||
t, err := time.Parse("2006-01-02", input.NextExecution)
|
||||
if err != nil {
|
||||
log.Error("transaction validate: %v", err)
|
||||
return nil, fmt.Errorf("could not parse timestamp: %w", ErrBadRequest)
|
||||
}
|
||||
|
||||
t = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
|
||||
nextExecution = &t
|
||||
}
|
||||
|
||||
transactionRecurring := types.TransactionRecurring{
|
||||
Id: id,
|
||||
UserId: userId,
|
||||
|
||||
IntervalMonths: intervalMonths,
|
||||
Active: active,
|
||||
LastExecution: nil,
|
||||
NextExecution: nextExecution,
|
||||
|
||||
Party: input.Party,
|
||||
Description: input.Description,
|
||||
|
||||
Reference in New Issue
Block a user