Wire Stage 3 reports to real data
Created getReportData server action to fetch Orders, ManualSales, and Expenses from database. Split reports page into server component (fetches data) and client component (renders charts). Reports now display actual business data instead of mock data - monthly profit, expense breakdown, and cash flow tables. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
339b2d960e
commit
39f54dedee
@@ -0,0 +1,26 @@
|
||||
'use server';
|
||||
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import { isAdminAuthenticated } from '@/lib/adminAuth';
|
||||
|
||||
export async function getReportData() {
|
||||
const isAuthenticated = await isAdminAuthenticated();
|
||||
if (!isAuthenticated) throw new Error('Unauthorized');
|
||||
|
||||
const [orders, manualSales, expenses] = await Promise.all([
|
||||
prisma.order.findMany({
|
||||
select: { id: true, total: true, createdAt: true },
|
||||
orderBy: { createdAt: 'asc' },
|
||||
}),
|
||||
prisma.manualSale.findMany({
|
||||
select: { id: true, total: true, soldAt: true, createdAt: true },
|
||||
orderBy: { soldAt: 'desc' },
|
||||
}),
|
||||
prisma.expense.findMany({
|
||||
select: { id: true, amount: true, date: true, category: true },
|
||||
orderBy: { date: 'desc' },
|
||||
}),
|
||||
]);
|
||||
|
||||
return { orders, manualSales, expenses };
|
||||
}
|
||||
Reference in New Issue
Block a user