Transaction Delete and Existance

Christopher Vollick created

Now that Transaction acts as a kind of repo, there's two other methods
I'm going to want for the future.

Change summary

lib/transaction.rb | 14 ++++++++++++++
1 file changed, 14 insertions(+)

Detailed changes

lib/transaction.rb 🔗

@@ -23,6 +23,20 @@ class Transaction
 		end
 	end
 
+	def delete
+		ids = [@transaction_id, "bonus_for_#{@transaction_id}"]
+		DB.query_defer(<<~SQL, ids)
+			DELETE FROM transactions WHERE transaction_id IN ($1, $2)
+		SQL
+	end
+
+	def exists?
+		DB.query_one(<<~SQL, @transaction_id).then { |r| r[:count] == 1 }
+			SELECT COUNT(1) FROM transactions
+			WHERE transaction_id = $1
+		SQL
+	end
+
 	def total
 		amount + bonus
 	end