Handle inexistant location page

This commit is contained in:
2022-06-24 12:26:38 +02:00
parent 4c0b7101ea
commit 3e13a86581

View File

@@ -16,14 +16,14 @@ export const photoFields = `
export async function get({ params }: RequestEvent): Promise<RequestHandlerOutput> {
try {
const { location } = params
const { location: slug } = params
// Query
const res = await fetchAPI(`
query {
location (
filter: {
slug: { _eq: "${location}" },
slug: { _eq: "${slug}" },
status: { _eq: "published" },
}
) {
@@ -47,7 +47,7 @@ export async function get({ params }: RequestEvent): Promise<RequestHandlerOutpu
photos: photo (
filter: {
location: { slug: { _eq: "${location}" }}
location: { slug: { _eq: "${slug}" }}
},
sort: "-date_created",
limit: ${import.meta.env.VITE_LIST_AMOUNT},
@@ -57,19 +57,22 @@ export async function get({ params }: RequestEvent): Promise<RequestHandlerOutpu
}
# Total
total_published: photo_aggregated (filter: { location: { slug: { _eq: "${location}" }}}) {
total_published: photo_aggregated (filter: { location: { slug: { _eq: "${slug}" }}}) {
count { location }
}
}
`)
const { data: { location, photos, total_published } } = res
const { data } = res
if (!location.length) {
return { status: 404 }
}
return {
body: {
location: data.location[0],
photos: data.photos,
totalPhotos: data.photos.length ? data.total_published[0].count.location : 0,
location: location[0],
photos: photos,
totalPhotos: photos.length ? total_published[0].count.location : 0,
}
}
} catch (error) {