Add comprehensive analytics system with: - Analytics data layer (aggregator, metrics, trends, cache) - 6 API endpoints (overview, plants, transport, farms, sustainability, export) - 6 chart components (LineChart, BarChart, PieChart, AreaChart, Gauge, Heatmap) - 5 dashboard widgets (KPICard, TrendIndicator, DataTable, DateRangePicker, FilterPanel) - 5 dashboard pages (overview, plants, transport, farms, sustainability) - Export functionality (CSV, JSON) Dependencies added: recharts, d3, date-fns Also includes minor fixes: - Fix EnvironmentalForm spread type error - Fix AgentOrchestrator Map iteration issues - Fix next.config.js image domains undefined error - Add downlevelIteration to tsconfig
41 lines
992 B
TypeScript
41 lines
992 B
TypeScript
/**
|
|
* Analytics Overview API
|
|
* Returns aggregated overview metrics for the dashboard
|
|
*/
|
|
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import { getAnalyticsOverview, AnalyticsFilters, TimeRange } from '../../../lib/analytics';
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
if (req.method !== 'GET') {
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
|
}
|
|
|
|
try {
|
|
const timeRange = (req.query.timeRange as TimeRange) || '30d';
|
|
|
|
const filters: AnalyticsFilters = {
|
|
timeRange,
|
|
};
|
|
|
|
const overview = await getAnalyticsOverview(filters);
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
data: overview,
|
|
meta: {
|
|
timeRange,
|
|
generatedAt: new Date().toISOString(),
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error('Analytics overview error:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Failed to fetch analytics overview',
|
|
});
|
|
}
|
|
}
|