From 1b7a0cbe80e149d585e14dcdcd4ffd9fb38ef511 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 17 Jan 2024 10:51:12 -0500 Subject: [PATCH] Allow custom settled after time for tx --- lib/transaction.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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