localgreenchain/pages/api/notifications/stats.ts
Claude 62c1ded598
Add comprehensive notification system (Agent 8)
Implement multi-channel notification system with:
- Core notification service with email, push, and in-app channels
- Email templates for all notification types (welcome, plant registered,
  transport alerts, farm alerts, harvest ready, demand matches, weekly digest)
- Push notification support with VAPID authentication
- In-app notification management with read/unread tracking
- Notification scheduler for recurring and scheduled notifications
- API endpoints for notifications CRUD, preferences, and subscriptions
- UI components (NotificationBell, NotificationList, NotificationItem,
  PreferencesForm)
- Full notifications page with preferences management
- Service worker for push notification handling
2025-11-23 03:52:41 +00:00

49 lines
1.4 KiB
TypeScript

/**
* API: Notification Statistics Endpoint
* GET /api/notifications/stats - Get notification statistics
*/
import type { NextApiRequest, NextApiResponse } from 'next';
import { getNotificationService, getNotificationScheduler } from '../../../lib/notifications';
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' });
}
try {
const notificationService = getNotificationService();
const scheduler = getNotificationScheduler();
// In production, get userId from session/auth
const userId = req.query.userId as string || 'demo-user';
const serviceStats = notificationService.getStats();
const schedulerStats = scheduler.getStats();
const userNotifications = notificationService.getUserNotifications(userId);
const unreadCount = notificationService.getUnreadCount(userId);
const scheduledForUser = scheduler.getScheduledForUser(userId);
return res.status(200).json({
success: true,
data: {
user: {
total: userNotifications.length,
unread: unreadCount,
scheduled: scheduledForUser.length
},
global: serviceStats,
scheduler: schedulerStats
}
});
} catch (error: any) {
return res.status(500).json({
success: false,
error: error.message
});
}
}