From 227873cee84824db1f22b2338740767ab92a34ed Mon Sep 17 00:00:00 2001 From: ReaSlyn Date: Fri, 16 May 2025 10:48:01 +0200 Subject: [PATCH] feat: add all others talks for speakers --- app/pages/api/talks/me.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/pages/api/talks/me.ts b/app/pages/api/talks/me.ts index bc7a4bb..73d3a67 100644 --- a/app/pages/api/talks/me.ts +++ b/app/pages/api/talks/me.ts @@ -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);