🚧 Migrate to new SvelteKit routing system
A bit annoying but for the best I guess?
This commit is contained in:
56
src/routes/shop/+page.server.ts
Normal file
56
src/routes/shop/+page.server.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { error } from '@sveltejs/kit'
|
||||
import type { PageServerLoad } from './$types'
|
||||
import { fetchAPI } from '$utils/api'
|
||||
import { getProduct } from '$utils/functions/swell'
|
||||
import { getRandomItem } from '$utils/functions'
|
||||
|
||||
export const load: PageServerLoad = async ({}) => {
|
||||
try {
|
||||
// Get content from API
|
||||
const data = await fetchAPI(`
|
||||
query {
|
||||
posters: product (
|
||||
filter: { status: { _eq: "published" }}
|
||||
) {
|
||||
name
|
||||
type
|
||||
description
|
||||
details
|
||||
location {
|
||||
name
|
||||
slug
|
||||
}
|
||||
product_id
|
||||
photos_product {
|
||||
directus_files_id {
|
||||
id
|
||||
title
|
||||
}
|
||||
}
|
||||
photos_preview {
|
||||
directus_files_id {
|
||||
id
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
if (data) {
|
||||
const randomPoster = getRandomItem(data.data.posters)
|
||||
|
||||
// Fetch Swell API for product
|
||||
const shopProduct = await getProduct(randomPoster.product_id)
|
||||
|
||||
if (shopProduct) {
|
||||
return {
|
||||
product: randomPoster,
|
||||
shopProduct,
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
throw error(500, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user