From 476a34fb695029a4adff526c8aecb311c8b21543 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 4 Jun 2019 23:47:10 +0200 Subject: [PATCH] Changed the order of execution between getting tmdb movie and searching plex for it. Now we await tmdb movie and then check if exists in plex. This is better when we miss plex request --- .../src/webserver/controllers/info/movieInfo.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/seasoned_api/src/webserver/controllers/info/movieInfo.js b/seasoned_api/src/webserver/controllers/info/movieInfo.js index 3607285..896f656 100644 --- a/seasoned_api/src/webserver/controllers/info/movieInfo.js +++ b/seasoned_api/src/webserver/controllers/info/movieInfo.js @@ -12,11 +12,15 @@ const plex = new Plex(configuration.get('plex', 'ip')); * @param {Response} res * @returns {Callback} */ -function movieInfoController(req, res) { +async function movieInfoController(req, res) { const movieId = req.params.id; - tmdb.movieInfo(movieId) - .then((movie) => plex.existsInPlex(movie)) - .then((movie) => { + const { credits } = req.query; + const movie = await tmdb.movieInfo(movieId, credits); + + plex.existsInPlex(movie) + .catch((error) => { console.log('Error when searching plex'); }) + .then(() => { + console.log('movie', movie) res.send(movie); }).catch((error) => { res.status(404).send({ success: false, error: error.message });