summaryrefslogtreecommitdiff
path: root/lib/contact-possible-items/validations.ts
blob: 609be0df9a625fdd9efe918e37798d37a04e0886 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
import { createSearchParamsCache, parseAsInteger, parseAsString } from "nuqs/server"
import { z } from "zod"

// 검색 파라미터 스키마 (뷰 기반으로 수정)
export const searchParamsSchema = z.object({
  page: z.coerce.number().default(1),
  per_page: z.coerce.number().default(10),
  sort: z.string().optional(),
  search: z.string().optional(), // 통합 검색
  contactName: z.string().optional(),
  vendorName: z.string().optional(),
  itemCode: z.string().optional(),
  vendorCode: z.string().optional(),
  workType: z.string().optional(),
  from: z.string().optional(),
  to: z.string().optional(),
})

// searchParams 캐시 생성
export const searchParamsCache = createSearchParamsCache({
  page: parseAsInteger.withDefault(1),
  per_page: parseAsInteger.withDefault(10),
  sort: parseAsString.withDefault(""),
  search: parseAsString.withDefault(""), // 통합 검색 추가
  contactName: parseAsString.withDefault(""),
  vendorName: parseAsString.withDefault(""),
  itemCode: parseAsString.withDefault(""),
  vendorCode: parseAsString.withDefault(""),
  workType: parseAsString.withDefault(""),
  from: parseAsString.withDefault(""),
  to: parseAsString.withDefault(""),
})

export type SearchParamsCache = typeof searchParamsCache

// 담당자별 아이템 생성용 스키마 (FK만 사용)
export const contactPossibleItemSchema = z.object({
  contactId: z.number().min(1, "담당자를 선택해주세요"),
  vendorPossibleItemId: z.number().min(1, "벤더 가능 아이템을 선택해주세요"),
})

export type ContactPossibleItemSchema = z.infer<typeof contactPossibleItemSchema> 

// 조회용 스키마 (searchParamsCache와 일치하도록 수정)
export const getContactPossibleItemsSchema = z.object({
  page: z.number().default(1),
  per_page: z.number().default(10),
  sort: z.string().optional(),
  search: z.string().optional(),
  contactName: z.string().optional(),
  vendorName: z.string().optional(),
  itemCode: z.string().optional(),
  vendorCode: z.string().optional(),
  workType: z.string().optional(),
  from: z.string().optional(),
  to: z.string().optional(),
})

export type GetContactPossibleItemsSchema = z.infer<typeof getContactPossibleItemsSchema>