summaryrefslogtreecommitdiff
path: root/lib/items-ship/validations.ts
blob: cb297f99d1166557d643facd18e1b8fa6fa10950 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import {
  createSearchParamsCache,
  parseAsArrayOf,
  parseAsInteger,
  parseAsString,
  parseAsStringEnum,
} from "nuqs/server"
import * as z from "zod"

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

export const searchParamsCache = createSearchParamsCache({
  flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault(
    []
  ),
  page: parseAsInteger.withDefault(1),
  perPage: parseAsInteger.withDefault(10),
  sort: getSortingStateParser<Item>().withDefault([
    { id: "createdAt", desc: true },
  ]),
  itemCode: parseAsString.withDefault(""),
  itemName: parseAsString.withDefault(""),
  description: parseAsString.withDefault(""),

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

})

export const createItemSchema = z.object({
  itemCode: z.string(),
  itemName: z.string(),
  description: z.string(),
})

export const updateItemSchema = z.object({
  itemCode: z.string(),
  itemName: z.string().optional(),
  description: z.string().optional(),
})

// 조선 아이템 업데이트 스키마
export const updateShipbuildingItemSchema = z.object({
  itemCode: z.string(),
  itemName: z.string().optional(),
  description: z.string().optional(),
  workType: z.string().optional(),
  shipTypes: z.string().optional(),
})


export type GetItemsSchema = Awaited<ReturnType<typeof searchParamsCache.parse>>
export type CreateItemSchema = z.infer<typeof createItemSchema>
export type UpdateItemSchema = z.infer<typeof updateItemSchema>
export type UpdateShipbuildingItemSchema = z.infer<typeof updateShipbuildingItemSchema>

// 조선 아이템 스키마
export const createShipbuildingItemSchema = z.object({
  itemCode: z.string(),
  itemName: z.string(),
  description: z.string(),
  workType: z.string(),
  shipTypes: z.string(),
})


export type CreateShipbuildingItemSchema = z.infer<typeof createShipbuildingItemSchema>

// 기본 아이템 생성 데이터 타입
export interface ItemCreateData {
  itemCode: string
  itemName: string
  description: string | null
}


// 조선 아이템 생성 데이터 타입
export interface ShipbuildingItemCreateData extends ItemCreateData {
  workType: string | null
  shipTypes: string | null
}

// 아이템 타입에 따른 생성 데이터 타입
export type TypedItemCreateData = ShipbuildingItemCreateData