fix(admin): filter duplicate daily puzzles in dashboard
This commit is contained in:
@@ -42,7 +42,20 @@ export async function GET() {
|
||||
}
|
||||
}));
|
||||
|
||||
return NextResponse.json(formattedPuzzles);
|
||||
// Filter out duplicates (keep only the first one per category)
|
||||
// This matches the behavior of getOrCreateDailyPuzzle which uses findFirst
|
||||
const uniquePuzzles = [];
|
||||
const seenCategories = new Set();
|
||||
|
||||
for (const puzzle of formattedPuzzles) {
|
||||
const key = `${puzzle.categoryType}-${puzzle.genreId || 'null'}-${puzzle.specialId || 'null'}`;
|
||||
if (!seenCategories.has(key)) {
|
||||
seenCategories.add(key);
|
||||
uniquePuzzles.push(puzzle);
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json(uniquePuzzles);
|
||||
} catch (error) {
|
||||
console.error('Error fetching daily puzzles:', error);
|
||||
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
|
||||
|
||||
Reference in New Issue
Block a user