import { NextRequest, NextResponse } from 'next/server' import prisma from '@/lib/prisma' import { auth } from '@/auth' export async function GET( request: NextRequest, { params }: { params: Promise<{ sessionId: string }> } ) { const authSession = await auth() if (!authSession?.user?.id) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) } try { const { sessionId } = await params const brainstormSession = await prisma.brainstormSession.findFirst({ where: { id: sessionId, OR: [ { userId: authSession.user.id }, { participants: { some: { userId: authSession.user.id } } }, { shares: { some: { userId: authSession.user.id, status: 'accepted' } } }, ], } as any, select: { id: true }, }) if (!brainstormSession) { return NextResponse.json({ error: 'Not found' }, { status: 404 }) } const snapshots = await prisma.brainstormSnapshot.findMany({ where: { sessionId }, orderBy: { step: 'asc' }, select: { id: true, step: true, label: true, activityId: true, ideaGraph: true, createdAt: true, }, }) return NextResponse.json({ success: true, data: snapshots }) } catch (error) { console.error('Error fetching snapshots:', error) return NextResponse.json( { error: 'Failed to fetch snapshots' }, { status: 500 } ) } }