Use aggregated data from Directus to count photos on Location page

This commit is contained in:
2021-10-12 00:06:55 +02:00
parent 80a972253f
commit ab6227b7e6

View File

@@ -210,6 +210,7 @@
}, },
limit: ${import.meta.env.VITE_LIST_AMOUNT}, limit: ${import.meta.env.VITE_LIST_AMOUNT},
) { ) {
id
name name
slug slug
description description
@@ -243,24 +244,21 @@
date_created date_created
} }
total_published: photo ( total_published: photo_aggregated (groupBy: "location") {
filter: { group
status: { _eq: "published" }, count { id }
location: { slug: { _eq: "${location}" }}
}
) {
id
} }
} }
`) `)
const { data } = res const { data } = res
const locationPhotosCount = data.total_published.find(({ group }: any) => group.id === data.location.id)
return { return {
props: { props: {
data: data.location[0], data: data.location[0],
photos: data.photos, photos: data.photos,
totalPhotos: data.total_published.length, totalPhotos: locationPhotosCount.count.id,
lastUpdated: data.photos[0].date_created, lastUpdated: data.photos[0].date_created,
} }
} }