Skip to content
Snippets Groups Projects
Commit e983cab2 authored by Bilel El Yaagoubi's avatar Bilel El Yaagoubi
Browse files

add cast to infos

parent 72a39034
No related branches found
No related tags found
1 merge request!10add cast to infos
Pipeline #42505 passed
...@@ -16,6 +16,7 @@ const MovieSchema = new mongoose.Schema( ...@@ -16,6 +16,7 @@ const MovieSchema = new mongoose.Schema(
video: { type: Boolean }, video: { type: Boolean },
vote_average: { type: Number }, vote_average: { type: Number },
vote_count: { type: Number }, vote_count: { type: Number },
cast: { type: Array },
}, },
{ {
toJSON: { virtuals: true }, // So `res.json()` and other `JSON.stringify()` functions include virtuals toJSON: { virtuals: true }, // So `res.json()` and other `JSON.stringify()` functions include virtuals
......
...@@ -22,6 +22,11 @@ async function populateMovies(movies) { ...@@ -22,6 +22,11 @@ async function populateMovies(movies) {
// TODO: populate movies into the database // TODO: populate movies into the database
try { try {
for (const movie of movies) { 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({ const newMovie = await new MovieModel({
// Movie attributes // Movie attributes
adult: movie.adult, adult: movie.adult,
...@@ -38,6 +43,7 @@ async function populateMovies(movies) { ...@@ -38,6 +43,7 @@ async function populateMovies(movies) {
video: movie.video, video: movie.video,
vote_average: movie.vote_average, vote_average: movie.vote_average,
vote_count: movie.vote_count, vote_count: movie.vote_count,
cast: castFetch.data.cast,
}); });
// Create a new movie instance // Create a new movie instance
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment