From e983cab29a38b94e588dce821dd428fdff0b9183 Mon Sep 17 00:00:00 2001 From: El Yaagoubi Bilel <bilel.el-yaagoubi@student-cs.fr> Date: Wed, 8 Jun 2022 15:32:12 +0200 Subject: [PATCH] add cast to infos --- backend/models/movie.js | 1 + backend/populate.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/backend/models/movie.js b/backend/models/movie.js index c50fb0d..12a7c81 100644 --- a/backend/models/movie.js +++ b/backend/models/movie.js @@ -16,6 +16,7 @@ const MovieSchema = new mongoose.Schema( video: { type: Boolean }, vote_average: { type: Number }, vote_count: { type: Number }, + cast: { type: Array }, }, { toJSON: { virtuals: true }, // So `res.json()` and other `JSON.stringify()` functions include virtuals diff --git a/backend/populate.js b/backend/populate.js index 4c5284a..1db1124 100644 --- a/backend/populate.js +++ b/backend/populate.js @@ -22,6 +22,11 @@ async function populateMovies(movies) { // TODO: populate movies into the database try { for (const movie of movies) { + const castFetch = await axios.get( + `https://api.themoviedb.org/3/movie/` + + movie.id + + `/credits?api_key=522d421671cf75c2cba341597d86403a` + ); const newMovie = await new MovieModel({ // Movie attributes adult: movie.adult, @@ -38,6 +43,7 @@ async function populateMovies(movies) { video: movie.video, vote_average: movie.vote_average, vote_count: movie.vote_count, + cast: castFetch.data.cast, }); // Create a new movie instance -- GitLab