diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-04-15 13:01:38 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-04-15 13:01:38 +0530 |
commit | 9c911e79c18d09224b90546ef29c2e9986e4cc0c (patch) | |
tree | 5de085d2c61a8e606caeb787dd391b3de5477fc4 /src/service/transaction.ts | |
parent | 549f75c9e271ca9b8b8f919ee996526b31e659a8 (diff) |
Added functionality to delete a transaction
Diffstat (limited to 'src/service/transaction.ts')
-rw-r--r-- | src/service/transaction.ts | 24 |
1 files changed, 23 insertions, 1 deletions
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 } |