From ea143fb32a4dd25e60f0f34d17144774247d0413 Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Mon, 27 Apr 2026 11:48:47 +0100 Subject: [PATCH] fix(backend): fetch credits in TMDB preview and fix collection fallback - Add credits fetch to GET /entries/tmdb/preview/:type/:tmdbId endpoint - Map cast/crew to Credit-like shapes in preview response - Fall back to entry backdrops when collection has no backdrop --- backend/controllers/entryController.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/backend/controllers/entryController.js b/backend/controllers/entryController.js index a2a761f..551c338 100644 --- a/backend/controllers/entryController.js +++ b/backend/controllers/entryController.js @@ -171,6 +171,30 @@ class EntryController { const data = await tmdbService.fetchEntryData(tmdbId, is_tvserie); if (!data) return res.status(404).json({ message: 'Entry not found on TMDB' }); + // Fetch credits in parallel + const creditsData = await tmdbService.fetchEntryCredits(tmdbId, is_tvserie); + + // Map credits to a shape similar to our Credit model + const credits = []; + if (creditsData?.cast) { + for (const c of creditsData.cast) { + credits.push({ + id: c.credit_id || c.id, + cast_type: 'cast', + character: is_tvserie + ? (c.roles?.[0]?.character || c.character || null) + : (c.character || null), + people_id: c.id, + people: { + id: c.id, + name: c.name || c.original_name, + profile_path: c.profile_path, + tmdb_id: c.id, + }, + }); + } + } + // Normalize to a shape similar to our Entry model const preview = { tmdb_id: data.id, @@ -192,6 +216,7 @@ class EntryController { networks: data.networks || [], homepage: data.homepage || null, imdb_id: data.imdb_id || data.external_ids?.imdb_id || null, + credits, }; res.status(200).json(preview);