96 lines
1.7 KiB
TypeScript
96 lines
1.7 KiB
TypeScript
import { prisma } from "@repo/db";
|
|
import { getServerSession } from "../../api/auth/[...nextauth]/auth";
|
|
import { EventCard } from "./_components/EventCard";
|
|
import { RocketIcon } from "@radix-ui/react-icons";
|
|
|
|
const page = async () => {
|
|
const session = await getServerSession();
|
|
if (!session) return null;
|
|
const user = session.user;
|
|
if (!user) return null;
|
|
|
|
const events = await prisma.event.findMany({
|
|
where: {
|
|
hidden: false,
|
|
},
|
|
include: {
|
|
Appointments: {
|
|
where: {
|
|
appointmentDate: {
|
|
gte: new Date(),
|
|
},
|
|
},
|
|
},
|
|
Participants: {
|
|
where: {
|
|
userId: user.id,
|
|
},
|
|
},
|
|
},
|
|
|
|
orderBy: {
|
|
id: "desc",
|
|
},
|
|
});
|
|
const appointments = await prisma.eventAppointment.findMany({
|
|
where: {
|
|
appointmentDate: {
|
|
gte: new Date(),
|
|
},
|
|
},
|
|
include: {
|
|
Participants: {
|
|
select: {
|
|
enscriptionDate: true,
|
|
id: true,
|
|
userId: true,
|
|
},
|
|
where: {
|
|
appointmentCancelled: false,
|
|
},
|
|
orderBy: {
|
|
enscriptionDate: "asc",
|
|
},
|
|
},
|
|
_count: {
|
|
select: {
|
|
Participants: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
const userAppointments = await prisma.eventAppointment.findMany({
|
|
where: {
|
|
Participants: {
|
|
some: {
|
|
userId: user.id,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return (
|
|
<div className="grid grid-cols-6 gap-4">
|
|
<div className="col-span-full">
|
|
<p className="flex items-center gap-2 text-left text-2xl font-semibold">
|
|
<RocketIcon className="h-5 w-5" /> Events & Kurse
|
|
</p>
|
|
</div>
|
|
|
|
{events.map((event) => {
|
|
return (
|
|
<EventCard
|
|
appointments={appointments}
|
|
selectedAppointments={userAppointments}
|
|
user={user}
|
|
event={event}
|
|
key={event.id}
|
|
/>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default page;
|