fix: harden booking and meeting flows
This commit is contained in:
+3
-2
@@ -13,13 +13,14 @@ import type { PayloadRequest } from "payload";
|
||||
*/
|
||||
export async function acquireBookingDayLock(req: PayloadRequest, dateKey: string): Promise<void> {
|
||||
const txID = req.transactionID ? String(await req.transactionID) : undefined;
|
||||
if (!txID) return; // No active transaction — nothing to lock against.
|
||||
if (!txID) throw new Error("A booking lock requires an active transaction");
|
||||
|
||||
const adapter = req.payload.db as unknown as {
|
||||
sessions?: Record<string, { db: { execute: (query: unknown) => Promise<unknown> } }>;
|
||||
drizzle: { execute: (query: unknown) => Promise<unknown> };
|
||||
};
|
||||
const tx = adapter.sessions?.[txID]?.db ?? adapter.drizzle;
|
||||
const tx = adapter.sessions?.[txID]?.db;
|
||||
if (!tx) throw new Error("Booking transaction not found");
|
||||
|
||||
await tx.execute(sql`SELECT pg_advisory_xact_lock(hashtext(${dateKey}))`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user