Fixed issue where a item would not be returned when nothing was found matching query in plex. Also moved checkId up in the request.

This commit is contained in:
2018-02-05 14:55:49 +01:00
parent 44878a295c
commit cfb878fa64

View File

@@ -111,6 +111,7 @@ class RequestRepository {
else if (type === 'tv') { tmdbType = 'tvInfo'}
return Promise.resolve()
.then(() => tmdb.lookup(identifier, tmdbType))
.then((tmdbMovie) => this.checkID(tmdbMovie))
.then((tmdbMovie) => {
return Promise.resolve(plexRepository.searchMedia(tmdbMovie.title))
.then((plexMovies) => {
@@ -122,35 +123,29 @@ class RequestRepository {
return tmdbMovie;
}
}
return tmdbMovie;
})
// Add it here
.catch((error) => {
console.log('there was a error:', error)
return tmdbMovie;
})
return tmdbMovie;
})
.catch((error) => {
console.log(error)
})
.then((item) => {
return this.checkID(item.id, item.type)
.then((result) => {
item.requested = result;
return item
})
})
}
checkID(id, type) {
return this.database.get(this.queries.checkIfIdRequested, [id, type])
checkID(tmdbMovie) {
return Promise.resolve()
.then(() => this.database.get(this.queries.checkIfIdRequested, [tmdbMovie.id, tmdbMovie.type]))
.then((result, error) => {
if (error) return false
let already_requested = false;
if (result)
return true
else
return false
already_requested = true
tmdbMovie.requested = already_requested;
return tmdbMovie;
})
}