summaryrefslogtreecommitdiff
path: root/lib/welding/validation.ts
blob: 969aafdc591db8a38202d359f5ea5993856b8ed2 (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
35
36
37
38
39
40
41
42
43
44
45
46
import {
    createSearchParamsCache,
    parseAsArrayOf,
    parseAsInteger,
    parseAsString,
    parseAsStringEnum,
} from "nuqs/server"
import * as z from "zod"

import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
import { OcrRow } from "@/db/schema";


// 검색 파라미터 캐시 정의
export const searchParamsCache = createSearchParamsCache({
  flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),
  page: parseAsInteger.withDefault(1),
  perPage: parseAsInteger.withDefault(10),
  
  // 확장된 타입으로 정렬 파서 사용
  sort: getSortingStateParser<OcrRow>().withDefault([
    { id: "createdAt", desc: true },
  ]),

  // 기존 필터 옵션들
  code: parseAsString.withDefault(""),
  label: parseAsString.withDefault(""),
  
  // 고급 필터
  filters: getFiltersStateParser().withDefault([]),
  joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
  search: parseAsString.withDefault(""),
});

// 타입 내보내기
export type GetOcrRowSchema = Awaited<ReturnType<typeof searchParamsCache.parse>>;


export const updateOcrRowSchema = z.object({
  identificationNo: z.string().optional(),
  tagNo: z.string().optional(), 
  weldingDate: z.string().optional(),
  jointType: z.string().optional(),
})

export type UpdateOcrRowSchema = z.infer<typeof updateOcrRowSchema>