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,19 +3,38 @@ import { prisma } from '@/lib/prisma';
|
|||||||
import AdminNav from '@/components/AdminNav';
|
import AdminNav from '@/components/AdminNav';
|
||||||
|
|
||||||
export default async function DesignsPage() {
|
export default async function DesignsPage() {
|
||||||
const designs = await prisma.designApproval.findMany({
|
let designs = [];
|
||||||
select: {
|
try {
|
||||||
id: true,
|
designs = await prisma.designApproval.findMany({
|
||||||
customerName: true,
|
select: {
|
||||||
customerEmail: true,
|
id: true,
|
||||||
designPreviewUrl: true,
|
customerName: true,
|
||||||
status: true,
|
customerEmail: true,
|
||||||
createdAt: true,
|
designPreviewUrl: true,
|
||||||
product: true,
|
status: true,
|
||||||
messages: { orderBy: { createdAt: 'desc' }, take: 1 },
|
createdAt: true,
|
||||||
},
|
productId: true,
|
||||||
orderBy: { createdAt: 'desc' },
|
},
|
||||||
});
|
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 pending = designs.filter((d) => d.status === 'PENDING');
|
||||||
const approved = designs.filter((d) => d.status === 'APPROVED');
|
const approved = designs.filter((d) => d.status === 'APPROVED');
|
||||||
|
|||||||
Reference in New Issue
Block a user