From 11626f25578e2bfafb2321add7be0838b51c4ca8 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sun, 17 Nov 2024 02:39:34 +1100 Subject: [PATCH] Implement delete transaction --- src/components/TransactionEditor.vue | 34 +++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/components/TransactionEditor.vue b/src/components/TransactionEditor.vue index d22bf6c..b221abb 100644 --- a/src/components/TransactionEditor.vue +++ b/src/components/TransactionEditor.vue @@ -86,7 +86,7 @@
- +
@@ -244,4 +244,36 @@ await getCurrentWindow().close(); } + + async function deleteTransaction() { + if (!confirm('Are you sure you want to delete this transaction? This operation is irreversible.')) { + return; + } + + const session = await db.load(); + + // Delete atomically + await session.execute( + `BEGIN; + + -- Cascade delete statement line reconciliations + DELETE FROM statement_line_reconciliations + WHERE posting_id IN ( + SELECT postings.id FROM postings WHERE transaction_id = $1 + ); + + -- Delete postings + DELETE FROM postings + WHERE transaction_id = $1; + + -- Delete transaction + DELETE FROM transactions + WHERE id = $1; + + COMMIT;`, + [transaction.id] + ); + + await getCurrentWindow().close(); + }