Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.
Merged
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
27 changes: 22 additions & 5 deletions app/pages/api/talks/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,34 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)

try {
// 3. Fetch all talks where the current user is the speaker
const talks = await prisma.talks.findMany({
const speakerTalks = await prisma.talks.findMany({
where: { speaker_id: userId },
include: {
subjects: true, // if you want the topic name
schedules: true, // if you want any scheduled slots
feedback: true, // feedback for each talk
favorites: true, // who favorited it
subjects: true,
schedules: true,
feedback: true,
favorites: true,
users: { select: { id: true, username: true, email: true } },
},
orderBy: { created_at: 'desc' },
});

// 4. Fetch all other talks (exclude talks where the user is the speaker)
const otherTalks = await prisma.talks.findMany({
where: { speaker_id: { not: userId } },
include: {
subjects: true,
schedules: true,
feedback: true,
favorites: true,
users: { select: { id: true, username: true, email: true } },
},
orderBy: { created_at: 'desc' },
});

// 5. Combine speakerTalks and otherTalks (no duplicates)
const talks = [...speakerTalks, ...otherTalks];

return res.status(200).json({ talks });
} catch (error) {
console.error('Error fetching user talks:', error);
Expand Down
Loading