pelagia-portal/App/app/api/notifications/route.ts
2026-05-18 23:18:58 +05:30

29 lines
762 B
TypeScript

import { auth } from "@/auth";
import { db } from "@/lib/db";
import { NextResponse } from "next/server";
export async function GET() {
const session = await auth();
if (!session?.user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const [notifications, unreadCount] = await Promise.all([
db.notification.findMany({
where: { userId: session.user.id },
orderBy: { sentAt: "desc" },
take: 20,
select: {
id: true,
body: true,
link: true,
isRead: true,
sentAt: true,
poId: true,
},
}),
db.notification.count({
where: { userId: session.user.id, isRead: false },
}),
]);
return NextResponse.json({ notifications, unreadCount });
}