diff --git a/app/api/songs/route.ts b/app/api/songs/route.ts index d68f5da..0414638 100644 --- a/app/api/songs/route.ts +++ b/app/api/songs/route.ts @@ -30,9 +30,19 @@ function curatorCanEditSong(context: StaffContext, song: any, assignments: { gen if (context.role === 'admin') return true; const songGenreIds = (song.genres || []).map((g: any) => g.id); - // `song.specials` enthält bereits `Special`-Objekte mit einem `id`-Feld. - // Wir verwenden daher konsistent `s.id` statt eines (nicht existenten) `specialId`. - const songSpecialIds = (song.specials || []).map((s: any) => s.id); + // `song.specials` kann je nach Context entweder ein Array von + // - `Special` (mit `id`) + // - `SpecialSong` (mit `specialId`) + // - `SpecialSong` (mit Relation `special.id`) + // sein. Wir normalisieren hier auf reine Zahlen-IDs. + const songSpecialIds = (song.specials || []) + .map((s: any) => { + if (s?.id != null) return s.id; + if (s?.specialId != null) return s.specialId; + if (s?.special?.id != null) return s.special.id; + return undefined; + }) + .filter((id: any): id is number => typeof id === 'number'); // Songs ohne Genres/Specials sind für Kuratoren generell editierbar if (songGenreIds.length === 0 && songSpecialIds.length === 0) { @@ -49,7 +59,14 @@ function curatorCanDeleteSong(context: StaffContext, song: any, assignments: { g if (context.role === 'admin') return true; const songGenreIds = (song.genres || []).map((g: any) => g.id); - const songSpecialIds = (song.specials || []).map((s: any) => s.id); + const songSpecialIds = (song.specials || []) + .map((s: any) => { + if (s?.id != null) return s.id; + if (s?.specialId != null) return s.specialId; + if (s?.special?.id != null) return s.special.id; + return undefined; + }) + .filter((id: any): id is number => typeof id === 'number'); const allGenresAllowed = songGenreIds.every((id: number) => assignments.genreIds.has(id)); const allSpecialsAllowed = songSpecialIds.every((id: number) => assignments.specialIds.has(id)); @@ -86,7 +103,9 @@ export async function GET(request: NextRequest) { visibleSongs = songs.filter(song => { const songGenreIds = song.genres.map(g => g.id); - const songSpecialIds = song.specials.map(ss => ss.specialId); + // `song.specials` ist hier ein Array von SpecialSong mit Relation `special`, + // wir nutzen konsistent die Special-ID. + const songSpecialIds = song.specials.map(ss => ss.special.id); // Songs ohne Genres/Specials sind immer sichtbar if (songGenreIds.length === 0 && songSpecialIds.length === 0) { diff --git a/app/curator/page.tsx b/app/curator/page.tsx index 210a003..cab78be 100644 --- a/app/curator/page.tsx +++ b/app/curator/page.tsx @@ -332,6 +332,12 @@ export default function CuratorPage() { setPlayingSongId(null); setAudioElement(null); }); + + // Reset Zustand, wenn der Track zu Ende gespielt ist + audio.onended = () => { + setPlayingSongId(null); + setAudioElement(null); + }; } };