feat: implement core platform features including business directory, admin dashboard, authentication, and API infrastructure
Some checks failed
Build and Push App / build (push) Failing after 16m2s
Some checks failed
Build and Push App / build (push) Failing after 16m2s
This commit is contained in:
@@ -37,14 +37,57 @@ export async function GET(
|
||||
// 3. Get monthly stats (views per day for last 30 days)
|
||||
const thirtyDaysAgo = new Date();
|
||||
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
|
||||
thirtyDaysAgo.setHours(0, 0, 0, 0);
|
||||
|
||||
// Note: Raw query might be needed for group by date in some DBs,
|
||||
// but for now we'll just return the totals for simplicity.
|
||||
const recentEvents = await prisma.analyticsEvent.findMany({
|
||||
where: {
|
||||
createdAt: { gte: thirtyDaysAgo },
|
||||
metadata: {
|
||||
path: ['businessId'],
|
||||
equals: id
|
||||
}
|
||||
},
|
||||
select: {
|
||||
type: true,
|
||||
createdAt: true
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'asc'
|
||||
}
|
||||
});
|
||||
|
||||
// 4. Process events into daily stats
|
||||
const statsMap = new Map<string, { date: string, views: number, clicks: number }>();
|
||||
|
||||
// Initialize last 30 days with 0
|
||||
for (let i = 0; i <= 30; i++) {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - i);
|
||||
const dateStr = date.toISOString().split('T')[0];
|
||||
const displayDate = date.toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' });
|
||||
statsMap.set(dateStr, { date: displayDate, views: 0, clicks: 0 });
|
||||
}
|
||||
|
||||
recentEvents.forEach(event => {
|
||||
const dateStr = event.createdAt.toISOString().split('T')[0];
|
||||
if (statsMap.has(dateStr)) {
|
||||
const dayStat = statsMap.get(dateStr)!;
|
||||
if (event.type === 'BUSINESS_VIEW') {
|
||||
dayStat.views++;
|
||||
} else if (event.type === 'BUSINESS_CONTACT_CLICK') {
|
||||
dayStat.clicks++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Convert Map to sorted array
|
||||
const dailyStats = Array.from(statsMap.values()).reverse(); // Older to newer
|
||||
|
||||
return NextResponse.json({
|
||||
businessId: id,
|
||||
totalViews,
|
||||
contactClicks,
|
||||
dailyStats,
|
||||
updatedAt: new Date().toISOString()
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user