Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/AtendedEventList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
"use server";
import Event from "@/lib/event";
import { auth } from "@/lib/auth";
import { EventList } from "./EventList";
import { headers } from "next/headers";

export default async function AttendedEventList() {
const events = await Event.findAll();
const session = await auth.api.getSession({
headers: await headers(),
});
const userId = session?.user?.id;
const events = userId ? await Event.findByAtendeeUserId(userId) : [];
Comment on lines +8 to +12
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AttendedEventList fetches the session itself. On pages that already call auth.api.getSession() (e.g. src/app/events/attended/page.tsx), this results in duplicate session lookups per request. Consider passing userId (or the session) into this component when available and only calling getSession as a fallback when the prop isn’t provided.

Copilot uses AI. Check for mistakes.

return <EventList events={events} />;
}
38 changes: 38 additions & 0 deletions src/lib/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,44 @@ export default class Event {
);
}

static async findByAtendeeUserId(
userId: string,
{
status,
atendeeStatuses = [AtendeeStatus.Attend, AtendeeStatus.Maybe],
}: { status?: EventStatus[]; atendeeStatuses?: AtendeeStatus[] } = {},
): Promise<Event[]> {
const events = await prisma.event.findMany({
where: {
...(status ? { status: { in: status } } : {}),
participants: {
some: {
userId,
status: { in: atendeeStatuses },
},
},
},
});

return events.map(
(event) =>
new Event({
id: event.id,
title: event.title,
description: event.description || undefined,
date: event.date,
startAt: event.startTime || undefined,
endAt: event.endTime || undefined,
registrationDeadline: event.registrationDeadline || undefined,
capacity: event.capacity || undefined,
location: event.location || undefined,
status: event.status as EventStatus,
createdAt: event.createdAt || undefined,
updatedAt: event.updatedAt || undefined,
}),
);
Comment on lines +220 to +248
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findByAtendeeUserId duplicates the same Prisma->Event mapping logic already used in create / findById / findAll. Adding another copy increases the chance of future drift when fields are added/renamed. Consider extracting a shared converter (e.g., a private fromDb(event) helper) and reusing it here and in the existing find methods.

Copilot uses AI. Check for mistakes.
}

async addAtendee(
userId: string,
status: AtendeeStatus = AtendeeStatus.Attend,
Expand Down
Loading