97 lines
2.7 KiB
TypeScript
97 lines
2.7 KiB
TypeScript
import { error } from '@sveltejs/kit'
|
|
import type { PageServerLoad } from './$types'
|
|
import { PUBLIC_LIST_AMOUNT } from '$env/static/public'
|
|
import { fetchAPI } from '$utils/api'
|
|
|
|
export const photoFields = `
|
|
title
|
|
slug
|
|
city
|
|
image {
|
|
id
|
|
title
|
|
width, height
|
|
}
|
|
date_taken
|
|
date_created
|
|
`
|
|
|
|
export const load: PageServerLoad = async ({ params }) => {
|
|
try {
|
|
const { location: slug } = params
|
|
|
|
// Query
|
|
const res = await fetchAPI(`
|
|
query {
|
|
location (
|
|
filter: {
|
|
slug: { _eq: "${slug}" },
|
|
status: { _eq: "published" },
|
|
},
|
|
) {
|
|
id
|
|
name
|
|
slug
|
|
description
|
|
date_updated
|
|
illustration_desktop { id }
|
|
illustration_desktop_2x { id }
|
|
illustration_mobile { id }
|
|
credits {
|
|
credit_id {
|
|
name
|
|
website
|
|
}
|
|
}
|
|
country {
|
|
name
|
|
slug
|
|
flag { id }
|
|
}
|
|
has_poster
|
|
acknowledgement
|
|
}
|
|
|
|
photos: photo (
|
|
filter: {
|
|
location: { slug: { _eq: "${slug}" }}
|
|
},
|
|
sort: "-date_created",
|
|
limit: ${PUBLIC_LIST_AMOUNT},
|
|
page: 1,
|
|
) {
|
|
${photoFields}
|
|
}
|
|
|
|
# Total
|
|
total_published: photo_aggregated (filter: { location: { slug: { _eq: "${slug}" }}}) {
|
|
count { location }
|
|
}
|
|
|
|
# Shop product
|
|
product (filter: { location: { slug: { _eq: "${slug}" }}}) {
|
|
photos_product {
|
|
directus_files_id {
|
|
id
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`)
|
|
|
|
const { data: { location: location, photos, total_published, product }} = res
|
|
|
|
if (!location.length || location.length && params.country !== location[0].country.slug) {
|
|
throw error(404, "This location is not available… yet!")
|
|
}
|
|
|
|
return {
|
|
location: location[0],
|
|
photos,
|
|
totalPhotos: photos.length ? total_published[0].count.location : 0,
|
|
product: product[0],
|
|
}
|
|
} catch (err) {
|
|
throw error(500, err)
|
|
}
|
|
} |