diff --git a/src/domains/Favorites/api/List/index.ts b/src/domains/Favorites/api/List/index.ts index 0152d8f..0241318 100644 --- a/src/domains/Favorites/api/List/index.ts +++ b/src/domains/Favorites/api/List/index.ts @@ -19,27 +19,21 @@ export const rawFavorites = async (): Promise => { const parseResponse = async ( rawResponse: RawResponse[], ): Promise => { - let response = [] as any[]; + const response = rawResponse.map(async (favorite: RawResponse) => { + // Get favorites details from TMDB API and merge + const details = await Details(favorite.movie_id); - // Parse API user favorites - rawResponse.forEach(favorite => { - const parsedFavorite = { + // Merge API and TMDB results + return { + ...details, id: favorite.id, userId: favorite.user_id, movieId: favorite.movie_id, }; - - response = [...response, parsedFavorite]; - }); - - // Get favorites details from TMDB API and merge - const parsedResponse = response.map(async (favorite: Response) => { - const details = await Details(favorite.movieId); - - return { ...details, ...favorite, id: favorite.id }; }); - const resolvedResponse = await Promise.all(parsedResponse); + // Resolve async requests and promises + const resolvedResponse = Promise.all(response); return resolvedResponse; }; diff --git a/src/screens/Home/index.tsx b/src/screens/Home/index.tsx index 05dd9a6..d4f3b5b 100644 --- a/src/screens/Home/index.tsx +++ b/src/screens/Home/index.tsx @@ -18,7 +18,6 @@ const Home: React.FC = () => { NowPlaying().then(response => setNowPlayingList(response)); Popular().then(response => setPopularList(response)); Favorites().then(response => { - console.log('response', response); setFavoriteList(response); }); }, []);