Skip to content

Commit

Permalink
chore(refactor): use repository for public posting
Browse files Browse the repository at this point in the history
  • Loading branch information
amandesai01 committed Sep 7, 2024
1 parent 6a23af9 commit 68db41f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
35 changes: 0 additions & 35 deletions app/composables/api.ts
Original file line number Diff line number Diff line change
@@ -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<GeneralSettings>('/api/settings/general', {
query: {
config,
},
});
}

export function usePublicPostings() {
return useFetch<JobPosting[]>('/api/public/postings');
}

export function usePublicPosting(id: string) {
const res = useFetch<JobPosting>('/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', {
Expand Down
32 changes: 32 additions & 0 deletions app/composables/postings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof createJobPostingSchema>;
export type UpdatePostingSchema = z.infer<typeof updateJobPostingSchema>;
export type FetchPostingSchema = z.infer<typeof fetchJobPostingFilterSchema>;
Expand All @@ -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,
});
}
2 changes: 1 addition & 1 deletion app/pages/postings/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 68db41f

Please sign in to comment.