Files
housesof/src/routes/shop/+layout.server.ts

73 lines
1.8 KiB
TypeScript

import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
import { fetchSwell } from '$utils/functions/shopServer'
export const load: PageServerLoad = async () => {
try {
// Get content from API
const res = await fetchAPI(`query {
shop {
page_heroimage { id }
}
location (
filter: {
has_poster: { _eq: true },
status: { _eq: "published" },
},
sort: "name"
) {
name
slug
}
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
}
}
}
}`)
const { data: { shop, location, posters }} = res
/**
* Get products data from Swell
*/
const shopProducts: any = await fetchSwell('/products', {
category: 'posters',
})
if (shopProducts) {
return {
shop,
locations: location,
posters,
shopProducts: shopProducts.results,
}
}
} catch (err) {
throw error(500, err.message)
}
}