-
Notifications
You must be signed in to change notification settings - Fork 0
参加登録済みページのバグ修正 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) : []; | ||
|
|
||
| return <EventList events={events} />; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
|
||
| } | ||
|
|
||
| async addAtendee( | ||
| userId: string, | ||
| status: AtendeeStatus = AtendeeStatus.Attend, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AttendedEventListfetches the session itself. On pages that already callauth.api.getSession()(e.g.src/app/events/attended/page.tsx), this results in duplicate session lookups per request. Consider passinguserId(or the session) into this component when available and only callinggetSessionas a fallback when the prop isn’t provided.