Added rating and release_date when parsing movies and fixed respective tests

This commit is contained in:
2019-11-03 20:56:46 +01:00
parent c589457a6c
commit f8cc19b510
6 changed files with 46 additions and 20 deletions

View File

@@ -1,14 +1,15 @@
class Movie {
constructor(id, title, year=undefined, overview=undefined, poster=undefined,
backdrop=undefined, rank=undefined, genres=undefined, productionStatus=undefined,
tagline=undefined, runtime=undefined, imdb_id=undefined, popularity) {
constructor(id, title, year=undefined, overview=undefined, poster=undefined, backdrop=undefined,
releaseDate=undefined, rating=undefined, genres=undefined, productionStatus=undefined,
tagline=undefined, runtime=undefined, imdb_id=undefined, popularity=undefined) {
this.id = id;
this.title = title;
this.year = year;
this.overview = overview;
this.poster = poster;
this.backdrop = backdrop;
this.rank = rank;
this.releaseDate = releaseDate;
this.rating = rating;
this.genres = genres;
this.productionStatus = productionStatus;
this.tagline = tagline;
@@ -19,13 +20,14 @@ class Movie {
}
static convertFromTmdbResponse(response) {
const { id, title, release_date, overview, poster_path, backdrop_path, rank, genres, status,
const { id, title, release_date, overview, poster_path, backdrop_path, vote_average, genres, status,
tagline, runtime, imdb_id, popularity } = response;
const year = new Date(release_date).getFullYear()
const releaseDate = new Date(release_date);
const year = releaseDate.getFullYear();
const genreNames = genres ? genres.map(g => g.name) : undefined
return new Movie(id, title, year, overview, poster_path, backdrop_path, rank, genreNames, status,
return new Movie(id, title, year, overview, poster_path, backdrop_path, releaseDate, vote_average, genreNames, status,
tagline, runtime, imdb_id, popularity)
}
@@ -34,7 +36,7 @@ class Movie {
const { title, year, rating, tagline, summary } = response;
const _ = undefined
return new Movie(null, title, year, summary, _, _, rating, _, _, tagline)
return new Movie(null, title, year, summary, _, _, _, rating, _, _, tagline)
}
createJsonResponse() {
@@ -45,7 +47,8 @@ class Movie {
overview: this.overview,
poster: this.poster,
backdrop: this.backdrop,
rank: this.rank,
release_date: this.releaseDate,
rating: this.rating,
genres: this.genres,
production_status: this.productionStatus,
tagline: this.tagline,

View File

@@ -32,11 +32,11 @@ function handleListResponse(response, res) {
.catch(error => handleError(error, res))
}
function fetchTmdbList(req, res, listName, type) {
function fetchTmdbList(req, res, listname, type) {
const { page } = req.query;
if (type === 'movie') {
return tmdb.movieList(listName, page)
return tmdb.movieList(listname, page)
.then(listResponse => res.send(listResponse))
.catch(error => handleError(error, res))
} else if (type === 'show') {