Remove unused global photos count
This commit is contained in:
@@ -137,13 +137,6 @@
|
||||
) {
|
||||
count { id }
|
||||
}
|
||||
countTotalPhotosByLocation: photo_aggregated (
|
||||
groupBy: "location",
|
||||
filter: { status: { _eq: "published" }},
|
||||
) {
|
||||
group
|
||||
count { id }
|
||||
}
|
||||
countLocations: location_aggregated (
|
||||
filter: { status: { _eq: "published" }},
|
||||
) {
|
||||
@@ -156,32 +149,8 @@
|
||||
`)
|
||||
|
||||
const { data } = res
|
||||
|
||||
// Filter continents with linked countries
|
||||
const filteredContinents = data.continents.filter((cont: any) => cont.countries.length)
|
||||
|
||||
/**
|
||||
* For each photos count, find the country and add the sum to it
|
||||
*/
|
||||
// Add count key
|
||||
data.countries.forEach((country: any) => country.count = 0)
|
||||
|
||||
// Loop through totals by location
|
||||
data.countTotalPhotosByLocation.forEach(({ group, count }: { group: { location: number }, count: { id: number }}) => {
|
||||
const locationId = group.location
|
||||
const photosCount = Number(count.id)
|
||||
const countryIndex = data.countries.findIndex((country: any) => {
|
||||
// Find the location of a country
|
||||
return country.locations.find((location: any) => {
|
||||
// Match the count location ID to the country location ID
|
||||
return Number(location.id) === locationId
|
||||
})
|
||||
})
|
||||
|
||||
// Increment the count value found above
|
||||
data.countries[countryIndex].count += photosCount
|
||||
})
|
||||
|
||||
return {
|
||||
props: {
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user