- Archivierungs-Funktionalität: Kuratoren können Kommentare archivieren - archived-Flag in CuratorCommentRecipient hinzugefügt - API-Route für Archivieren: /api/curator-comments/[id]/archive - Kommentare werden beim initialen Laden automatisch abgerufen - Archivierte Kommentare werden nicht mehr in der Liste angezeigt - Archivieren-Button in der UI hinzugefügt - Migration für archived-Feld - Übersetzungen für Archivierung (DE/EN)
90 lines
2.9 KiB
TypeScript
90 lines
2.9 KiB
TypeScript
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 non-archived comments for this curator, ordered by creation date (newest first)
|
|
const comments = await prisma.curatorCommentRecipient.findMany({
|
|
where: {
|
|
curatorId: curatorId,
|
|
archived: false
|
|
},
|
|
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 }
|
|
);
|
|
}
|
|
}
|
|
|