diff --git a/app/composables/api.ts b/app/composables/api.ts index 636b027..4c827ac 100644 --- a/app/composables/api.ts +++ b/app/composables/api.ts @@ -1,38 +1,3 @@ -import type { GeneralSettings } from '~~/shared/schemas/setting'; -import type { JobPosting } from '~~/server/db/schema'; - -export function useGeneralSettings(config?: string) { - return useFetch('/api/settings/general', { - query: { - config, - }, - }); -} - -export function usePublicPostings() { - return useFetch('/api/public/postings'); -} - -export function usePublicPosting(id: string) { - const res = useFetch('/api/public/posting', { query: { id } }); - watchEffect(() => { - if (res.error.value) { - if (res.error.value.statusCode == 404) { - throw createError({ - statusCode: 404, - statusMessage: 'Job posting not found.', - }); - } - console.error(res.error.value); - throw createError({ - statusCode: 500, - statusMessage: 'Error fetching job posting.', - }); - } - }); - return res; -} - export function useApplicationStatus(postingId: string) { const auth = useAuth(); return useFetch('/api/application-status', { diff --git a/app/composables/postings.ts b/app/composables/postings.ts index f6a2451..a41f0c4 100644 --- a/app/composables/postings.ts +++ b/app/composables/postings.ts @@ -45,6 +45,22 @@ export function usePostingsRepository() { }); } +export function usePublicPostingsRepository() { + return useObjectRepository< + Postings, + never, + never, + never, + never, + never, + never + >({ + key: 'postings', + fetchURL: '/api/public/postings', + initFn: () => [], + }); +} + export type CreatePostingSchema = z.infer; export type UpdatePostingSchema = z.infer; export type FetchPostingSchema = z.infer; @@ -67,3 +83,19 @@ export function usePostingRepository(query: FetchPostingSchema) { deleteURL: '/api/posting', }); } + +export function usePublicPostingRepository(query: FetchPostingSchema) { + return useObjectRepository< + JobPosting, + FetchPostingSchema, + never, + never, + never, + never, + never + >({ + key: `${query.id}-public-posting`, + fetchURL: '/api/public/posting', + fetchQuery: query, + }); +} diff --git a/app/pages/postings/[id].vue b/app/pages/postings/[id].vue index e6eadfc..e09fef3 100644 --- a/app/pages/postings/[id].vue +++ b/app/pages/postings/[id].vue @@ -4,7 +4,7 @@ const id = route.params.id as string; const { data: applicationStatus, refresh: refreshApplicationStatus } = useApplicationStatus(id); -const { data: posting } = usePublicPosting(id); +const { data: posting } = await usePublicPostingRepository({ id }); const { data: careerSiteConfig } = useCareerSiteConfigObjectState(); const companyLogo = useRemoteAsset(careerSiteConfig.value.logo).url;