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