From 77bd1ddaadb4d12cd7289e3dacb5e69e61263696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Faneca?= Date: Sat, 1 Jun 2024 00:52:38 +0100 Subject: [PATCH] [#51] Fix: Error deleting tagged transactions --- src/controllers/transactionController.ts | 1 + src/services/transactionService.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/controllers/transactionController.ts b/src/controllers/transactionController.ts index 814ee2e..ea353ff 100644 --- a/src/controllers/transactionController.ts +++ b/src/controllers/transactionController.ts @@ -83,6 +83,7 @@ const createTransactionSchema = joi.object({ const createTransaction = async (req, res, next) => { try { + await new Promise(resolve => setTimeout(resolve, 5000)); const sessionData = await CommonsController.checkAuthSessionValidity(req); const trx = await createTransactionSchema.validateAsync(req.body); await TransactionService.createTransaction(sessionData.userId, { diff --git a/src/services/transactionService.ts b/src/services/transactionService.ts index 351d11f..1393f86 100644 --- a/src/services/transactionService.ts +++ b/src/services/transactionService.ts @@ -406,6 +406,13 @@ const deleteTransaction = async (userId: bigint, transactionId: number, dbClient throw APIError.notFound(`Account could not be found.`); } + // Delete trx references from transaction_has_tags + await prismaTx.transaction_has_tags.deleteMany({ + where: { + transactions_transaction_id: transactionId, + } + }); + // Delete transaction await prismaTx.transactions.delete({ where: { @@ -743,11 +750,11 @@ const getAllTransactionsForUserInCategoryAndInMonth = async ( AND (transactions.type = ${type} OR transactions.type = 'T') AND transactions.date_timestamp >= ${DateTimeUtils.getUnixTimestampFromDate( - minDate - )} + minDate + )} AND transactions.date_timestamp <= ${DateTimeUtils.getUnixTimestampFromDate( - maxDate - )} + maxDate + )} GROUP BY transaction_id ORDER BY transactions.date_timestamp DESC`;