import { NextRequest, NextResponse } from 'next/server'; import { PrismaClient } from '@prisma/client'; import { requireStaffAuth } from '@/lib/auth'; const prisma = new PrismaClient(); export async function GET(request: NextRequest) { // Require curator authentication const { error, context } = await requireStaffAuth(request); if (error || !context) { return error!; } // Only curators can view comments (not admins directly) if (context.role !== 'curator') { return NextResponse.json( { error: 'Only curators can view comments' }, { status: 403 } ); } try { const curatorId = context.curator.id; // Get all comments for this curator, ordered by creation date (newest first) const comments = await prisma.curatorCommentRecipient.findMany({ where: { curatorId: curatorId }, include: { comment: { include: { puzzle: { include: { song: { select: { title: true, artist: true } }, genre: { select: { id: true, name: true } } } } } } }, orderBy: { comment: { createdAt: 'desc' } } }); // Format the response const formattedComments = comments.map(recipient => ({ id: recipient.comment.id, message: recipient.comment.message, createdAt: recipient.comment.createdAt, readAt: recipient.readAt, puzzle: { id: recipient.comment.puzzle.id, date: recipient.comment.puzzle.date, song: { title: recipient.comment.puzzle.song.title, artist: recipient.comment.puzzle.song.artist }, genre: recipient.comment.puzzle.genre ? { id: recipient.comment.puzzle.genre.id, name: recipient.comment.puzzle.genre.name } : null } })); return NextResponse.json(formattedComments); } catch (error) { console.error('Error fetching curator comments:', error); return NextResponse.json( { error: 'Internal Server Error' }, { status: 500 } ); } }