feat: Implement user signup API and analytics dashboard with summary API, map, and chart components, updating dependencies.
This commit is contained in:
@@ -190,6 +190,13 @@ export async function GET(request: NextRequest) {
|
||||
return acc;
|
||||
}, {} as Record<string, number>);
|
||||
|
||||
// Generate last 7 days for sparkline
|
||||
const last7Days = Array.from({ length: 7 }, (_, i) => {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - (6 - i));
|
||||
return date.toISOString().split('T')[0];
|
||||
});
|
||||
|
||||
// QR performance (only show DYNAMIC QR codes since STATIC don't track scans)
|
||||
const qrPerformance = qrCodes
|
||||
.filter(qr => qr.type === 'DYNAMIC')
|
||||
@@ -204,6 +211,18 @@ export async function GET(request: NextRequest) {
|
||||
// Calculate trend
|
||||
const trendData = calculateTrend(currentTotal, previousTotal);
|
||||
|
||||
// Calculate sparkline data (scans per day for last 7 days)
|
||||
const sparklineData = last7Days.map(date => {
|
||||
return qr.scans.filter(s =>
|
||||
new Date(s.ts).toISOString().split('T')[0] === date
|
||||
).length;
|
||||
});
|
||||
|
||||
// Find last scanned date
|
||||
const lastScanned = qr.scans.length > 0
|
||||
? new Date(Math.max(...qr.scans.map(s => new Date(s.ts).getTime())))
|
||||
: null;
|
||||
|
||||
return {
|
||||
id: qr.id,
|
||||
title: qr.title,
|
||||
@@ -215,6 +234,8 @@ export async function GET(request: NextRequest) {
|
||||
: 0,
|
||||
trend: trendData.trend,
|
||||
trendPercentage: trendData.percentage,
|
||||
sparkline: sparklineData,
|
||||
lastScanned: lastScanned?.toISOString() || null,
|
||||
...(trendData.isNew && { isNew: true }),
|
||||
};
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user