Gwk-Cultural-Park/pages/api/career.ts

47 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-09-07 01:40:25 +00:00
// API: Career
import { projectId } from 'lib/sanity.api'
import { createClient } from 'next-sanity'
const client = projectId
? createClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
apiVersion: process.env.NEXT_PUBLIC_SANITY_API_VERSION,
useCdn: true,
token: process.env.SANITY_API_READ_TOKEN,
})
: null
// eslint-disable-next-line import/no-anonymous-default-export
export default async (req, res) => {
const query = `
*[_type == "careerSection"][1]{
title,
subtitle,
"coverImage":
coverImage.asset->path,
career[]->{
title,
"slug":slug.current,
content[],
"coverImage":
coverImage.asset->path,
date,
jobtype,
jobplatformurl,
author->{name},
"jobposter":posterImage.asset->url
}
}
`
try {
const data = await client.fetch(query)
res.status(200).json(data)
} catch (error) {
console.error('Error fetching Sanity data:', error)
res.status(500).json({ error: 'Error fetching Sanity data' })
}
}