diff --git a/App/app/(portal)/admin/vendors/actions.ts b/App/app/(portal)/admin/vendors/actions.ts index 7247043..2e4e8ba 100644 --- a/App/app/(portal)/admin/vendors/actions.ts +++ b/App/app/(portal)/admin/vendors/actions.ts @@ -173,12 +173,23 @@ export async function deleteVendor(id: string): Promise { }); if (blocked) return { error: "Cannot delete: vendor is referenced in submitted or active purchase orders." }; - await db.$transaction(async (tx) => { - await tx.purchaseOrder.updateMany({ where: { vendorId: id, status: "DRAFT" }, data: { vendorId: null } }); - await tx.product.updateMany({ where: { lastVendorId: id }, data: { lastVendorId: null } }); - await tx.productVendorPrice.deleteMany({ where: { vendorId: id } }); - await tx.vendor.delete({ where: { id } }); - }); + try { + await db.$transaction( + async (tx) => { + await tx.purchaseOrder.updateMany({ where: { vendorId: id, status: "DRAFT" }, data: { vendorId: null } }); + await tx.product.updateMany({ where: { lastVendorId: id }, data: { lastVendorId: null } }); + await tx.productVendorPrice.deleteMany({ where: { vendorId: id } }); + await tx.vendor.delete({ where: { id } }); + }, + { timeout: 30000 }, + ); + } catch (err: unknown) { + const code = (err as { code?: string })?.code; + if (code === "P2028") { + return { error: "Delete timed out — please try again." }; + } + throw err; + } revalidatePath("/admin/vendors"); return { ok: true };