export const dynamic = 'force-dynamic'; import { notFound } from 'next/navigation'; import { getCustomerById, getCustomerStats } from '@/lib/customers'; import { db } from '@/lib/db'; import { sales, customers } from '@/lib/db/schema'; import { eq, desc, and, sql } from 'drizzle-orm'; import { CustomerDetailClient } from './customer-detail-client'; type RouteContext = { params: Promise<{ id: string }> }; export default async function CustomerDetailPage({ params }: RouteContext) { const { id } = await params; const customerId = parseInt(id); if (isNaN(customerId)) notFound(); let customer; let stats; try { [customer, stats] = await Promise.all([ getCustomerById(customerId), getCustomerStats(customerId), ]); } catch { notFound(); } // Get purchase history const purchaseHistory = await db .select({ id: sales.id, saleNumber: sales.saleNumber, saleDate: sales.saleDate, totalAmount: sales.totalAmount, status: sales.status, paymentMethod: sales.paymentMethod, }) .from(sales) .where(eq(sales.customerId, customerId)) .orderBy(desc(sales.saleDate)) .limit(50); return ( ); }