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
36 lines
914 B
TypeScript
36 lines
914 B
TypeScript
/**
|
|
* API: Mark All Notifications as Read
|
|
* POST /api/notifications/read-all - Mark all notifications as read for user
|
|
*/
|
|
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import { getNotificationService } from '../../../lib/notifications';
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
if (req.method !== 'POST') {
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
|
}
|
|
|
|
try {
|
|
const notificationService = getNotificationService();
|
|
// In production, get userId from session/auth
|
|
const userId = req.body.userId || 'demo-user';
|
|
|
|
const count = notificationService.markAllAsRead(userId);
|
|
|
|
return res.status(200).json({
|
|
success: true,
|
|
data: {
|
|
markedAsRead: count
|
|
}
|
|
});
|
|
} catch (error: any) {
|
|
return res.status(500).json({
|
|
success: false,
|
|
error: error.message
|
|
});
|
|
}
|
|
}
|