From 1adeeb2a057992baa644a8d9ca738d6492647314 Mon Sep 17 00:00:00 2001 From: Amit Date: Thu, 23 May 2024 10:55:51 -0400 Subject: [PATCH] Fixed rollback and added --- callback-free-itx/script.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/callback-free-itx/script.ts b/callback-free-itx/script.ts index c1b3e6ca..6efc77e0 100644 --- a/callback-free-itx/script.ts +++ b/callback-free-itx/script.ts @@ -33,11 +33,10 @@ const prisma = new PrismaClient({ log: ["query"] }).$extends({ ) { const tx = prisma.$transaction((txClient) => { setTxClient(txClient as unknown as Prisma.TransactionClient); - - return txPromise.catch((e) => { - if (e === ROLLBACK) return; - throw e; - }); + return txPromise; + }).catch((e) => { + if (e === ROLLBACK) return; + throw e; }); // return a proxy TransactionClient with `$commit` and `$rollback` methods @@ -55,6 +54,11 @@ const prisma = new PrismaClient({ log: ["query"] }).$extends({ return tx; }; } + if (prop === "$transaction") { + return async (fn: (client: Prisma.TransactionClient) => Promise) => { + return fn(target); + }; + } return target[prop as keyof typeof target]; }, }) as FlatTransactionClient;