Files
housesof/src/routes/[country]/[location]/index.ts

76 lines
2.2 KiB
TypeScript

import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit'
import { fetchAPI } from '$utils/api'
export async function get({ params }: RequestEvent): Promise<RequestHandlerOutput> {
try {
const { location } = params
// Query
const res = await fetchAPI(`
query {
location (
filter: {
slug: { _eq: "${location}" },
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 }
has_poster
}
photos: photo (
filter: {
location: { slug: { _eq: "${location}" }}
},
sort: "-date_created",
limit: ${import.meta.env.VITE_LIST_AMOUNT},
page: 1,
) {
title
slug
city
image {
id
title
}
date_taken
date_created
}
# Total
total_published: photo_aggregated (filter: { location: { slug: { _eq: "${location}" }}}) {
count { location }
}
}
`)
const { data } = res
return {
body: {
location: data.location[0],
photos: data.photos,
totalPhotos: data.photos.length ? data.total_published[0].count.location : 0,
}
}
} catch (error) {
return {
status: 404,
body: error,
}
}
}