summaryrefslogtreecommitdiff
path: root/lib/project-gtc/validations.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/project-gtc/validations.ts')
-rw-r--r--lib/project-gtc/validations.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/project-gtc/validations.ts b/lib/project-gtc/validations.ts
new file mode 100644
index 00000000..963ffdd4
--- /dev/null
+++ b/lib/project-gtc/validations.ts
@@ -0,0 +1,32 @@
+import * as z from "zod"
+import { createSearchParamsCache,
+ parseAsArrayOf,
+ parseAsInteger,
+ parseAsString,
+ parseAsStringEnum
+} from "nuqs/server"
+
+import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
+import { ProjectGtcView } from "@/db/schema"
+
+export const projectGtcSearchParamsSchema = createSearchParamsCache({
+ flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),
+ page: parseAsInteger.withDefault(1),
+ perPage: parseAsInteger.withDefault(10),
+ sort: getSortingStateParser<ProjectGtcView>().withDefault([
+ { id: "projectCreatedAt", desc: true },
+ ]),
+
+ // advanced filter
+ filters: getFiltersStateParser().withDefault([]),
+ joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
+ search: parseAsString.withDefault(""),
+})
+
+export const projectGtcFileSchema = z.object({
+ projectId: z.number().min(1, "프로젝트 ID는 필수입니다."),
+ file: z.instanceof(File).refine((file) => file.size > 0, "파일은 필수입니다."),
+})
+
+export type ProjectGtcSearchParams = Awaited<ReturnType<typeof projectGtcSearchParamsSchema.parse>>
+export type ProjectGtcFileInput = z.infer<typeof projectGtcFileSchema> \ No newline at end of file