blob: f53bbbbffd5da102a813a784921fd6be92078e9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
// app/api/notifications/read-all/route.ts
import { NextRequest, NextResponse } from 'next/server';
import { getServerSession } from 'next-auth';
import { authOptions } from "@/app/api/auth/[...nextauth]/route"
export async function PATCH(request: NextRequest) {
try {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const notifications = await markAllNotificationsAsRead(session.user.id);
return NextResponse.json({
success: true,
updatedCount: notifications.length
});
} catch (error) {
console.error('Error marking all notifications as read:', error);
return NextResponse.json(
{ error: 'Failed to mark all notifications as read' },
{ status: 500 }
);
}
}
|