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
This commit is contained in:
Mohammed Abad committed 2026-04-27 11:48:47 +01:00
1 parent 23bce5a681
commit ea143fb32a
1 file changed
+25
+25
View File
@@ -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);