From 0d2e874f142c6f8cae449a518355a7bc05a4b6a0 Mon Sep 17 00:00:00 2001 From: Andymick Date: Sat, 18 Jul 2026 19:11:19 +0100 Subject: [PATCH] Fetch designs without relations to avoid database corruption issues Query designs and products separately instead of using Prisma relations, which allows the page to load even if there's corrupted data in the table. Co-Authored-By: Claude Haiku 4.5 --- src/app/admin/designs/page.tsx | 45 ++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/app/admin/designs/page.tsx b/src/app/admin/designs/page.tsx index 185c4d6..2fbd0ee 100644 --- a/src/app/admin/designs/page.tsx +++ b/src/app/admin/designs/page.tsx @@ -3,19 +3,38 @@ import { prisma } from '@/lib/prisma'; import AdminNav from '@/components/AdminNav'; export default async function DesignsPage() { - const designs = await prisma.designApproval.findMany({ - select: { - id: true, - customerName: true, - customerEmail: true, - designPreviewUrl: true, - status: true, - createdAt: true, - product: true, - messages: { orderBy: { createdAt: 'desc' }, take: 1 }, - }, - orderBy: { createdAt: 'desc' }, - }); + let designs = []; + try { + designs = await prisma.designApproval.findMany({ + select: { + id: true, + customerName: true, + customerEmail: true, + designPreviewUrl: true, + status: true, + createdAt: true, + productId: true, + }, + orderBy: { createdAt: 'desc' }, + }); + + // Fetch products separately to avoid relation issues + const productIds = [...new Set(designs.map(d => d.productId))]; + const products = await prisma.product.findMany({ + where: { id: { in: productIds } }, + select: { id: true, name: true }, + }); + const productMap = Object.fromEntries(products.map(p => [p.id, p])); + + // Add product to each design + designs = designs.map(d => ({ + ...d, + product: productMap[d.productId], + messages: [], + })) as any; + } catch (err) { + console.error('Error fetching designs:', err); + } const pending = designs.filter((d) => d.status === 'PENDING'); const approved = designs.filter((d) => d.status === 'APPROVED');