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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
ca11baf1ae
commit
0d2e874f14
@@ -3,7 +3,9 @@ import { prisma } from '@/lib/prisma';
|
||||
import AdminNav from '@/components/AdminNav';
|
||||
|
||||
export default async function DesignsPage() {
|
||||
const designs = await prisma.designApproval.findMany({
|
||||
let designs = [];
|
||||
try {
|
||||
designs = await prisma.designApproval.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
customerName: true,
|
||||
@@ -11,12 +13,29 @@ export default async function DesignsPage() {
|
||||
designPreviewUrl: true,
|
||||
status: true,
|
||||
createdAt: true,
|
||||
product: true,
|
||||
messages: { orderBy: { createdAt: 'desc' }, take: 1 },
|
||||
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');
|
||||
const rejected = designs.filter((d) => d.status === 'REJECTED');
|
||||
|
||||
Reference in New Issue
Block a user