Conversation
| return axios | ||
| .get(url) | ||
| .then((res) => { | ||
| .then(async (res) => { |
There was a problem hiding this comment.
Can we factor this out into its own separate function?
| const { result } = res.data; | ||
| const photos = result.photos || []; | ||
| // Limit to 10 photos. To remove limit, change to restaurant.photos = photos; | ||
| restaurant.photos = photos.slice(0, 10); |
There was a problem hiding this comment.
This slicing should go somewhere else. No data received by a Google Places API call should be thrown away. Maybe add it to the part where we create the Restaurant object (rather than GoogleRestaurant)
There was a problem hiding this comment.
I'll just remove the slice for now. I'm thinking we save everything but then when we display, we only display like 10.
| const { result } = res.data; | ||
| const photos = result.photos || []; | ||
| // Limit to 10 photos. To remove limit, change to restaurant.photos = photos; | ||
| restaurant.photos = photos.slice(0, 10); |
There was a problem hiding this comment.
Whenever we do a call to an external API, we want to immediately save the data it returns in as raw of a format as possible to minimize the chance of data loss. So the GoogleRestaurant object shouldn't be touched. Instead, we should add this after we've completed the save of the GoogleRestaurant. Preferably it goes something like this:
query google places for restaurants -> immediately turn the result into a GoogleRestaurant object and save -> do the place photos query -> immediately save those into their own object, perhaps call it GoogleRestaurantImage -> finally take the results of all the previous steps and construct a Restaurant object and save that
No description provided.