Only fetch published photos and locations
All checks were successful
continuous-integration/drone/push Build is passing

- Globally for photos
- For sitemap locations and photos
This commit is contained in:
2020-04-22 12:01:52 +02:00
parent 8231ea20a7
commit 3c364814df
4 changed files with 5 additions and 5 deletions

View File

@@ -47,13 +47,13 @@ export async function get (req, res, next) {
baseURL = `http${(req.httpVersion >= 2) ? 's' : ''}://${req.headers.host}`
// Get locations
const locationsReq = await fetch(`${apiEndpoints.rest}/items/locations?fields=slug,country.slug,modified_on`)
const locationsReq = await fetch(`${apiEndpoints.rest}/items/locations?fields=slug,country.slug,modified_on&status=published`)
const locationsData = await locationsReq.json()
const locations = locationsData.data
// Add last modified date to each location from its last photo
const updatedLocations = locations.map(async (location, i) => {
const latestPhotoReq = await fetch(`${apiEndpoints.rest}/items/photos?fields=created_on&limit=1&sort=created_on&filter[location.slug][rlike]=%${location.slug}`)
const latestPhotoReq = await fetch(`${apiEndpoints.rest}/items/photos?fields=created_on&limit=1&sort=created_on&status=published&filter[location.slug][rlike]=%${location.slug}`)
const latestPhotoData = await latestPhotoReq.json()
const latestPhoto = latestPhotoData.data[0]
location.updated = latestPhoto ? latestPhoto.created_on : location.modified_on