Behebe zwei Bugs im Kurator-Kommentar-System
Bug 1: Special-Kuratoren für Special-Puzzles berücksichtigen - Kommentare zu Special-Puzzles werden jetzt korrekt an Special-Kuratoren geroutet - Logik erweitert: Prüft zuerst puzzle.specialId, dann genreId, dann global - Special-Kuratoren werden über CuratorSpecial abgerufen Bug 2: Prisma Schema konsistent mit Migration - onDelete: SetNull zur genre-Relation in CuratorComment hinzugefügt - Entspricht jetzt dem Foreign Key Constraint in der Migration
This commit is contained in:
@@ -96,11 +96,12 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
// Determine responsible curators
|
// Determine responsible curators
|
||||||
const finalGenreId = genreId !== null && genreId !== undefined ? Number(genreId) : puzzle.genreId;
|
const finalGenreId = genreId !== null && genreId !== undefined ? Number(genreId) : puzzle.genreId;
|
||||||
|
const specialId = puzzle.specialId;
|
||||||
|
|
||||||
let curatorIds: number[] = [];
|
let curatorIds: number[] = [];
|
||||||
|
const allCuratorIds = new Set<number>();
|
||||||
|
|
||||||
if (finalGenreId === null) {
|
// Get all global curators (always included)
|
||||||
// Global puzzle: Get all global curators
|
|
||||||
const globalCurators = await prisma.curator.findMany({
|
const globalCurators = await prisma.curator.findMany({
|
||||||
where: {
|
where: {
|
||||||
isGlobalCurator: true
|
isGlobalCurator: true
|
||||||
@@ -109,8 +110,21 @@ export async function POST(request: NextRequest) {
|
|||||||
id: true
|
id: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
curatorIds = globalCurators.map(c => c.id);
|
globalCurators.forEach(gc => allCuratorIds.add(gc.id));
|
||||||
} else {
|
|
||||||
|
// Check for special puzzle first (takes precedence)
|
||||||
|
if (specialId !== null) {
|
||||||
|
// Special puzzle: Get curators for this special + all global curators
|
||||||
|
const specialCurators = await prisma.curatorSpecial.findMany({
|
||||||
|
where: {
|
||||||
|
specialId: specialId
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
curatorId: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
specialCurators.forEach(cs => allCuratorIds.add(cs.curatorId));
|
||||||
|
} else if (finalGenreId !== null) {
|
||||||
// Genre puzzle: Get curators for this genre + all global curators
|
// Genre puzzle: Get curators for this genre + all global curators
|
||||||
const genreCurators = await prisma.curatorGenre.findMany({
|
const genreCurators = await prisma.curatorGenre.findMany({
|
||||||
where: {
|
where: {
|
||||||
@@ -120,22 +134,11 @@ export async function POST(request: NextRequest) {
|
|||||||
curatorId: true
|
curatorId: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const globalCurators = await prisma.curator.findMany({
|
|
||||||
where: {
|
|
||||||
isGlobalCurator: true
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Combine and deduplicate curator IDs
|
|
||||||
const allCuratorIds = new Set<number>();
|
|
||||||
genreCurators.forEach(cg => allCuratorIds.add(cg.curatorId));
|
genreCurators.forEach(cg => allCuratorIds.add(cg.curatorId));
|
||||||
globalCurators.forEach(gc => allCuratorIds.add(gc.id));
|
|
||||||
curatorIds = Array.from(allCuratorIds);
|
|
||||||
}
|
}
|
||||||
|
// else: Global puzzle - only global curators (already added above)
|
||||||
|
|
||||||
|
curatorIds = Array.from(allCuratorIds);
|
||||||
|
|
||||||
if (curatorIds.length === 0) {
|
if (curatorIds.length === 0) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ model CuratorComment {
|
|||||||
puzzleId Int
|
puzzleId Int
|
||||||
puzzle DailyPuzzle @relation(fields: [puzzleId], references: [id], onDelete: Cascade)
|
puzzle DailyPuzzle @relation(fields: [puzzleId], references: [id], onDelete: Cascade)
|
||||||
genreId Int?
|
genreId Int?
|
||||||
genre Genre? @relation(fields: [genreId], references: [id])
|
genre Genre? @relation(fields: [genreId], references: [id], onDelete: SetNull)
|
||||||
message String
|
message String
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user