37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
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) {
|
|
try {
|
|
// Authenticate user
|
|
const session = await getServerSession(authOptions);
|
|
if (!session || !session.user?.id) {
|
|
return NextResponse.json(
|
|
{ error: "Not authenticated" },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
const userId = session.user.id;
|
|
const notificationService = NotificationService.getInstance();
|
|
const success = await notificationService.markAllAsRead(userId);
|
|
|
|
if (!success) {
|
|
return NextResponse.json(
|
|
{ error: "Failed to mark all notifications as read" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
return NextResponse.json({ success: true });
|
|
} catch (error: any) {
|
|
console.error('Error marking all notifications as read:', error);
|
|
return NextResponse.json(
|
|
{ error: "Internal server error", message: error.message },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|