summaryrefslogtreecommitdiff
path: root/lib/project-gtc/validations.ts
blob: 963ffdd43fe46225576a135e022224fc6737a506 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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>