From 70f6497404e31bfeeac0ce8de317ae825583b865 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 4 Jun 2019 23:35:21 +0200 Subject: [PATCH] All converter function from tmdb to movie, show and person takes optional cast object and maps to response --- seasoned_api/src/tmdb/convertTmdbToMovie.js | 6 +++++- seasoned_api/src/tmdb/convertTmdbToPerson.js | 6 +++++- seasoned_api/src/tmdb/convertTmdbToShow.js | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/seasoned_api/src/tmdb/convertTmdbToMovie.js b/seasoned_api/src/tmdb/convertTmdbToMovie.js index 3e702a0..d9e4d5e 100644 --- a/seasoned_api/src/tmdb/convertTmdbToMovie.js +++ b/seasoned_api/src/tmdb/convertTmdbToMovie.js @@ -2,11 +2,15 @@ const Movie = require('src/tmdb/types/movie'); const tmdbSwitcher = (tmdbMovie, property) => tmdbMovie[property] -function convertTmdbToMovie(tmdbMovie) { +function convertTmdbToMovie(tmdbMovie, credits=undefined) { const movie = new Movie(tmdbMovie.id, tmdbMovie.title) movie.overview = tmdbMovie.overview; movie.rank = tmdbMovie.vote_average; + if (credits) { + movie.credits = credits; + } + if (tmdbMovie.release_date !== undefined) { movie.release_date = new Date(tmdbMovie.release_date); movie.year = movie.release_date.getFullYear(); diff --git a/seasoned_api/src/tmdb/convertTmdbToPerson.js b/seasoned_api/src/tmdb/convertTmdbToPerson.js index 5821c84..32e6911 100644 --- a/seasoned_api/src/tmdb/convertTmdbToPerson.js +++ b/seasoned_api/src/tmdb/convertTmdbToPerson.js @@ -1,7 +1,7 @@ const Person = require('src/tmdb/types/person'); const convertTmdbToMovie = require('src/tmdb/convertTmdbToMovie'); -function convertTmdbToPerson(tmdbPerson) { +function convertTmdbToPerson(tmdbPerson, cast=undefined) { const person = new Person(tmdbPerson.id, tmdbPerson.name); if (tmdbPerson.profile_path !== undefined) { @@ -20,6 +20,10 @@ function convertTmdbToPerson(tmdbPerson) { person.known_for = tmdbPerson.known_for.map(convertTmdbToMovie); } + if (cast) { + person.cast = cast.cast; + } + return person; } diff --git a/seasoned_api/src/tmdb/convertTmdbToShow.js b/seasoned_api/src/tmdb/convertTmdbToShow.js index 594f160..0bb0481 100644 --- a/seasoned_api/src/tmdb/convertTmdbToShow.js +++ b/seasoned_api/src/tmdb/convertTmdbToShow.js @@ -1,12 +1,16 @@ const Show = require('src/tmdb/types/show'); -function convertTmdbToShow(tmdbShow) { +function convertTmdbToShow(tmdbShow, credits=undefined) { const show = new Show(tmdbShow.id, tmdbShow.name) show.seasons = tmdbShow.number_of_seasons; show.episodes = tmdbShow.number_of_episodes; show.overview = tmdbShow.overview; show.rank = tmdbShow.vote_average; + if (credits) { + show.credits = credits + } + if (tmdbShow.genres !== undefined) { show.genres = tmdbShow.genres.map(genre => genre.name); }