-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(refactor): update dataflow for postings
- Loading branch information
1 parent
52ec789
commit 662d0b2
Showing
11 changed files
with
292 additions
and
142 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import type { z } from 'zod'; | ||
import type { JobPosting } from '~~/server/db/schema'; | ||
import type { | ||
createJobPostingSchema, | ||
deleteJobPostingSchema, | ||
fetchJobPostingFilterSchema, | ||
updateJobPostingSchema, | ||
} from '~~/shared/schemas/posting'; | ||
|
||
export type PostingLite = { id: string; title: string }; | ||
export type PostingsLite = PostingLite[]; | ||
export function usePostingsLiteRepository( | ||
options: { immediate?: boolean } = { immediate: true } | ||
) { | ||
return useObjectRepository< | ||
PostingsLite, | ||
never, | ||
never, | ||
never, | ||
never, | ||
never, | ||
never | ||
>({ | ||
key: 'postings-lite', | ||
fetchURL: '/api/postings/lite', | ||
initFn: () => [], | ||
immediate: options.immediate, | ||
}); | ||
} | ||
|
||
export type Postings = JobPosting[]; | ||
export function usePostingsRepository() { | ||
return useObjectRepository< | ||
Postings, | ||
never, | ||
never, | ||
never, | ||
never, | ||
never, | ||
never | ||
>({ | ||
key: 'postings', | ||
fetchURL: '/api/postings', | ||
initFn: () => [], | ||
}); | ||
} | ||
|
||
export type CreatePostingSchema = z.infer<typeof createJobPostingSchema>; | ||
export type UpdatePostingSchema = z.infer<typeof updateJobPostingSchema>; | ||
export type FetchPostingSchema = z.infer<typeof fetchJobPostingFilterSchema>; | ||
export type DeletePostingSchema = z.infer<typeof deleteJobPostingSchema>; | ||
export function usePostingRepository(query: FetchPostingSchema) { | ||
return useObjectRepository< | ||
JobPosting, | ||
FetchPostingSchema, | ||
UpdatePostingSchema, | ||
never, | ||
CreatePostingSchema, | ||
never, | ||
DeletePostingSchema | ||
>({ | ||
key: `${query.id}-posting`, | ||
fetchURL: '/api/posting', | ||
fetchQuery: query, | ||
postURL: '/api/posting', | ||
updateURL: '/api/posting', | ||
deleteURL: '/api/posting', | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.