From 9c911e79c18d09224b90546ef29c2e9986e4cc0c Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Tue, 15 Apr 2025 13:01:38 +0530 Subject: Added functionality to delete a transaction --- src/service/transaction.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/service/transaction.ts') diff --git a/src/service/transaction.ts b/src/service/transaction.ts index 29a9faa..8f1c99d 100644 --- a/src/service/transaction.ts +++ b/src/service/transaction.ts @@ -42,7 +42,29 @@ const read = async (userId: Number, type: String) => { }) } +// TODO: ig collaborated transactions would need more logic +const del = async (userId: Number, transactionId: String) => { + const t = await prisma.transaction.findUnique({ + // @ts-ignore + where: { id: transactionId } + }) + + if (t) { + if (t.userId == userId) { + return prisma.transaction.delete({ + // @ts-ignore + where: { id: transactionId } + }) + } else { + throw new Error("403") + } + } else { + throw new Error("404") + } +} + export { create, - read + read, + del } -- cgit v1.2.3