diff --git a/lib/transaction.rb b/lib/transaction.rb index 8a16e082341f01ad41edfdbbad648085671a3809..ff9618daaa5c33d3c8fd052f6c17ebf207677c11 100644 --- a/lib/transaction.rb +++ b/lib/transaction.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true class Transaction - def initialize(customer_id, id, amount, note) + def initialize(customer_id, id, amount, note, settled_after: Time.now) @customer_id = customer_id @id = id @amount = amount @note = note + @after = settled_after end def bonus @@ -33,12 +34,12 @@ class Transaction end def save - args = [@customer_id, @id, @amount, @note] + args = [@customer_id, @id, @amount, @note, @after] DB.exec_params(<<-SQL, args).cmd_tuples.positive? INSERT INTO transactions (customer_id, transaction_id, settled_after, amount, note) VALUES - ($1, $2, LOCALTIMESTAMP, $3, $4) + ($1, $2, $5, $3, $4) ON CONFLICT (transaction_id) DO NOTHING SQL end