summaryrefslogtreecommitdiff
path: root/lib/docu-list-rule/code-groups/validation.ts
blob: 9745841cc93b97228a1fe0cb6f92957e87700e06 (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
33
34
import {
  createSearchParamsCache,
  parseAsArrayOf,
  parseAsInteger,
  parseAsString,
  parseAsStringEnum,
} from "nuqs/server"
import * as z from "zod"

import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
import { codeGroups } from "@/db/schema/docu-list-rule";

export const searchParamsCodeGroupsCache = createSearchParamsCache({
  flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault(
    []
  ),
  page: parseAsInteger.withDefault(1),
  perPage: parseAsInteger.withDefault(10),
  sort: getSortingStateParser<typeof codeGroups.$inferSelect>().withDefault([
    { id: "groupId", desc: false },
  ]),

  groupId: parseAsString.withDefault(""),
  description: parseAsString.withDefault(""),
  controlType: parseAsString.withDefault(""),
  isActive: parseAsString.withDefault(""),

  // advanced filter
  filters: getFiltersStateParser().withDefault([]),
  joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
  search: parseAsString.withDefault(""),
})

export type GetCodeGroupsSchema = Awaited<ReturnType<typeof searchParamsCodeGroupsCache.parse>>