Update/frontend logic #30 #33

Merged
KevinMidboe merged 19 commits from update/frontend_logic into master 2017-09-26 22:47:26 +00:00
Showing only changes of commit d787fba024 - Show all commits

View File

@@ -22,20 +22,20 @@ class TMDB {
return Promise.resolve() return Promise.resolve()
.then(() => this.tmdb(type, query)) // Search the tmdb api .then(() => this.tmdb(type, query)) // Search the tmdb api
.catch(() => { throw new Error('Could not search for movies.'); }) // If any error at all when fetching .catch(() => { throw new Error('Could not search for movies.'); }) // If any error at all when fetching
.then((reponse) => { .then((response) => {
try { try {
// We want to filter because there are movies really low rated that are not interesting to us. // We want to filter because there are movies really low rated that are not interesting to us.
let filteredTmdbItems = reponse.results.filter(function(tmdbResultItem) { let filteredTmdbItems = response.results.filter(function(tmdbResultItem) {
return ((tmdbResultItem.vote_count >= 80 || tmdbResultItem.popularity > 18) && (tmdbResultItem.release_date !== undefined || tmdbResultItem.first_air_date !== undefined)) return ((tmdbResultItem.vote_count >= 80 || tmdbResultItem.popularity > 18) && (tmdbResultItem.release_date !== undefined || tmdbResultItem.first_air_date !== undefined))
}) })
// Here we convert the filtered result from the tmdb api to seaonsed objects // Here we convert the filtered result from the tmdb api to seaonsed objects
let seasonedItems = filteredTmdbItems.map((tmdbItem) => { let seasonedItems = filteredTmdbItems.map((tmdbItem) => {
return convertTmdbToSeasoned(tmdbItem); return convertTmdbToSeasoned(tmdbItem, type);
}); });
// TODO add page number if results are larger than 20 // TODO add page number if results are larger than 20
return { 'results': seasonedItems, 'number_of_items_on_page': seasonedItems, return { 'results': seasonedItems, 'number_of_items_on_page': seasonedItems.length,
'page': 1, 'total_pages': 1 }; 'page': 1, 'total_pages': 1 };
} catch (parseError) { } catch (parseError) {