Shumiland/src/lib/getHomeData.ts
Vadym Samoilenko 66f9a0d645
Some checks are pending
CI / Type Check (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Unit Tests (push) Waiting to run
Deploy / Build & Push Image (push) Waiting to run
Deploy / Deploy to VPS (push) Blocked by required conditions
fix(build): remove .js extensions from payload.config imports + fix TS errors
payload.config.ts used explicit .js extensions on local imports which Turbopack
and webpack cannot resolve to .ts files without extensionAliases config. Revert
to extension-less imports (original pattern from first Payload commit) that both
bundlers handle natively.

Also fix two TypeScript strict-mode errors:
- seed/route.ts: doc.id (number) cast to string via String() instead of `as string`
- getHomeData.ts: Payload HomePage vs HomePageGlobal cast via `as unknown as`

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 18:34:38 +01:00

68 lines
1.9 KiB
TypeScript

import { cache } from 'react'
import { getPayload } from 'payload'
import configPromise from '@payload-config'
import type { HomePageGlobal, LocationCMS, ReviewCMS, BirthdayPackageCMS } from '@/types/globals'
export interface HomeData {
home: HomePageGlobal | null
locations: LocationCMS[]
reviews: ReviewCMS[]
birthdayPackages: BirthdayPackageCMS[]
}
export const getHomeData = cache(async (): Promise<HomeData> => {
try {
const payload = await getPayload({ config: configPromise })
const [home, locResult, revResult, pkgResult] = await Promise.all([
payload.findGlobal({ slug: 'home-page' }) as unknown as Promise<HomePageGlobal>,
payload.find({
collection: 'locations',
where: { showOnHome: { equals: true } },
sort: 'sort',
limit: 20,
overrideAccess: true,
}),
payload.find({
collection: 'reviews',
where: { showOnHome: { equals: true } },
sort: 'sort',
limit: 20,
overrideAccess: true,
}),
payload.find({
collection: 'birthday-packages',
sort: 'sort',
limit: 10,
overrideAccess: true,
}),
])
return {
home,
locations: locResult.docs as unknown as LocationCMS[],
reviews: revResult.docs as unknown as ReviewCMS[],
birthdayPackages: pkgResult.docs as unknown as BirthdayPackageCMS[],
}
} catch {
return { home: null, locations: [], reviews: [], birthdayPackages: [] }
}
})
export function getHeaderLocations() {
return cache(async (): Promise<LocationCMS[]> => {
try {
const payload = await getPayload({ config: configPromise })
const result = await payload.find({
collection: 'locations',
where: { showInMenu: { equals: true } },
sort: 'sort',
limit: 20,
overrideAccess: true,
})
return result.docs as unknown as LocationCMS[]
} catch {
return []
}
})()
}