diff --git a/app/api/songs/route.ts b/app/api/songs/route.ts index 831b35a..ea8236b 100644 --- a/app/api/songs/route.ts +++ b/app/api/songs/route.ts @@ -35,11 +35,15 @@ function curatorCanEditSong(context: StaffContext, song: any, assignments: { gen // - `SpecialSong` (mit `specialId`) // - `SpecialSong` (mit Relation `special.id`) // sein. Wir normalisieren hier auf reine Zahlen-IDs. + // WICHTIG: Bei SpecialSong-Objekten ist s.id die SpecialSong-ID, nicht die Special-ID! + // Daher zuerst specialId oder special.id prüfen. const songSpecialIds = (song.specials || []) .map((s: any) => { - if (s?.id != null) return s.id; + // Priorität: specialId oder special.id (die tatsächliche Special-ID) if (s?.specialId != null) return s.specialId; if (s?.special?.id != null) return s.special.id; + // Nur wenn es direkt ein Special-Objekt ist (nicht SpecialSong), verwende s.id + if (s?.id != null && s?.specialId == null && s?.special == null) return s.id; return undefined; }) .filter((id: any): id is number => typeof id === 'number'); @@ -59,11 +63,15 @@ function curatorCanDeleteSong(context: StaffContext, song: any, assignments: { g if (context.role === 'admin') return true; const songGenreIds = (song.genres || []).map((g: any) => g.id); + // WICHTIG: Bei SpecialSong-Objekten ist s.id die SpecialSong-ID, nicht die Special-ID! + // Daher zuerst specialId oder special.id prüfen. const songSpecialIds = (song.specials || []) .map((s: any) => { - if (s?.id != null) return s.id; + // Priorität: specialId oder special.id (die tatsächliche Special-ID) if (s?.specialId != null) return s.specialId; if (s?.special?.id != null) return s.special.id; + // Nur wenn es direkt ein Special-Objekt ist (nicht SpecialSong), verwende s.id + if (s?.id != null && s?.specialId == null && s?.special == null) return s.id; return undefined; }) .filter((id: any): id is number => typeof id === 'number'); @@ -382,7 +390,11 @@ export async function PUT(request: Request) { where: { id: Number(id) }, include: { genres: true, - specials: true, + specials: { + include: { + special: true + } + }, }, });