Files

46 lines
1.3 KiB
TypeScript

import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { redirect } from "next/navigation";
import MuayThaiDashboard from "./dashboard";
export default async function MuayThaiPage() {
const session = await getServerSession(authOptions);
if (!session?.user) redirect("/login");
const user = await prisma.user.findUnique({
where: { id: session.user.id },
include: {
muayThai: {
include: {
sessions: { orderBy: { date: "desc" }, take: 20 },
},
},
certificates: { orderBy: { createdAt: "desc" } },
absences: { orderBy: { date: "desc" } },
homework: { orderBy: { createdAt: "desc" } },
},
});
if (!user) redirect("/login");
const messages = await prisma.message.findMany({
orderBy: { createdAt: "desc" },
where: {
OR: [{ category: null }, { category: "general" }, { category: "muay-thai" }],
},
include: {
readBy: { where: { userId: user.id } },
},
});
const unreadCount = messages.filter((m) => m.readBy.length === 0).length;
return (
<MuayThaiDashboard
user={user}
messages={messages.map((m) => ({ ...m, isRead: m.readBy.length > 0 }))}
unreadCount={unreadCount}
/>
);
}