import { NextResponse } from 'next/server'; import { getServerSession } from 'next-auth'; import { authOptions } from "@/app/api/auth/options"; import { NotificationService } from '@/lib/services/notifications/notification-service'; // POST /api/notifications/read-all export async function POST(request: Request) { const startTime = Date.now(); try { console.log('[NOTIFICATION_API] Mark all as read endpoint called'); // Authenticate user const session = await getServerSession(authOptions); if (!session || !session.user?.id) { console.log('[NOTIFICATION_API] Mark all as read - Authentication failed'); return NextResponse.json( { error: "Not authenticated" }, { status: 401 } ); } const userId = session.user.id; console.log('[NOTIFICATION_API] Mark all as read - Processing', { userId, timestamp: new Date().toISOString() }); const notificationService = NotificationService.getInstance(); const success = await notificationService.markAllAsRead(userId); const duration = Date.now() - startTime; if (!success) { console.log('[NOTIFICATION_API] Mark all as read - Failed', { userId, duration: `${duration}ms` }); return NextResponse.json( { error: "Failed to mark all notifications as read" }, { status: 400 } ); } console.log('[NOTIFICATION_API] Mark all as read - Success', { userId, duration: `${duration}ms` }); return NextResponse.json({ success: true }); } catch (error: any) { const duration = Date.now() - startTime; console.error('[NOTIFICATION_API] Mark all as read - Error', { error: error.message, stack: error.stack, duration: `${duration}ms` }); return NextResponse.json( { error: "Internal server error", message: error.message }, { status: 500 } ); } }