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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
import {
createSearchParamsCache,
parseAsArrayOf,
parseAsInteger,
parseAsString,
parseAsStringEnum,
} from "nuqs/server"
import * as z from "zod"
import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
import { ItemOffshoreTop, ItemOffshoreHull, ItemShipbuilding } from "@/db/schema/items";
// 조선 아이템 검색 파라미터 캐시
export const shipbuildingSearchParamsCache = createSearchParamsCache({
flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),
page: parseAsInteger.withDefault(1),
perPage: parseAsInteger.withDefault(10),
sort: getSortingStateParser<ItemShipbuilding>().withDefault([
{ id: "createdAt", desc: true },
]),
itemCode: parseAsString.withDefault(""),
workType: parseAsString.withDefault(""),
shipTypes: parseAsString.withDefault(""),
itemList: parseAsString.withDefault(""),
filters: getFiltersStateParser().withDefault([]),
joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
search: parseAsString.withDefault(""),
})
// 해양 TOP 아이템 검색 파라미터 캐시
export const offshoreTopSearchParamsCache = createSearchParamsCache({
flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),
page: parseAsInteger.withDefault(1),
perPage: parseAsInteger.withDefault(10),
sort: getSortingStateParser<ItemOffshoreTop>().withDefault([
{ id: "createdAt", desc: true },
]),
itemCode: parseAsString.withDefault(""),
workType: parseAsString.withDefault(""),
itemList: parseAsString.withDefault(""),
subItemList: parseAsString.withDefault(""),
filters: getFiltersStateParser().withDefault([]),
joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
search: parseAsString.withDefault(""),
})
// 해양 HULL 아이템 검색 파라미터 캐시
export const offshoreHullSearchParamsCache = createSearchParamsCache({
flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),
page: parseAsInteger.withDefault(1),
perPage: parseAsInteger.withDefault(10),
sort: getSortingStateParser<ItemOffshoreHull>().withDefault([
{ id: "createdAt", desc: true },
]),
itemCode: parseAsString.withDefault(""),
workType: parseAsString.withDefault(""),
itemList: parseAsString.withDefault(""),
subItemList: parseAsString.withDefault(""),
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().optional(),
itemName: z.string().optional(),
description: z.string().nullish(),
})
// 조선 아이템 업데이트 스키마
export const updateShipbuildingItemSchema = z.object({
itemCode: z.string(),
itemName: z.string().optional(),
description: z.string().optional(),
workType: z.string().optional(),
shipTypes: z.string().optional(),
itemList: z.string().optional(),
})
export type GetShipbuildingSchema = Awaited<ReturnType<typeof shipbuildingSearchParamsCache.parse>>
export type GetOffshoreTopSchema = Awaited<ReturnType<typeof offshoreTopSearchParamsCache.parse>>
export type GetOffshoreHullSchema = Awaited<ReturnType<typeof offshoreHullSearchParamsCache.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(),
itemList: z.string().optional(),
})
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
itemList?: string | null
}
// 아이템 타입에 따른 생성 데이터 타입
export type TypedItemCreateData = ShipbuildingItemCreateData
// 해양 TOP 아이템 스키마
export const createOffshoreTopItemSchema = z.object({
itemCode: z.string(),
itemName: z.string(),
description: z.string(),
workType: z.enum(["TM", "TS", "TE", "TP"]),
itemList: z.string().optional(),
subItemList: z.string().optional(),
})
// 해양 HULL 아이템 스키마
export const createOffshoreHullItemSchema = z.object({
itemCode: z.string(),
itemName: z.string(),
description: z.string(),
workType: z.enum(["HA", "HE", "HH", "HM", "NC"]),
itemList: z.string().optional(),
subItemList: z.string().optional(),
})
export type CreateOffshoreTopItemSchema = z.infer<typeof createOffshoreTopItemSchema>
export type CreateOffshoreHullItemSchema = z.infer<typeof createOffshoreHullItemSchema>
// 해양 TOP 아이템 업데이트 스키마
export const updateOffshoreTopItemSchema = z.object({
itemCode: z.string(),
itemName: z.string().optional(),
description: z.string().optional(),
workType: z.enum(["TM", "TS", "TE", "TP"]).optional(),
itemList: z.string().optional(),
subItemList: z.string().optional(),
})
// 해양 HULL 아이템 업데이트 스키마
export const updateOffshoreHullItemSchema = z.object({
itemCode: z.string(),
itemName: z.string().optional(),
description: z.string().optional(),
workType: z.enum(["HA", "HE", "HH", "HM", "NC"]).optional(),
itemList: z.string().optional(),
subItemList: z.string().optional(),
})
export type UpdateOffshoreTopItemSchema = z.infer<typeof updateOffshoreTopItemSchema>
export type UpdateOffshoreHullItemSchema = z.infer<typeof updateOffshoreHullItemSchema>
// 해양 TOP 아이템 생성 데이터 타입
export interface OffshoreTopItemCreateData extends ItemCreateData {
workType: "TM" | "TS" | "TE" | "TP"
itemList?: string | null
subItemList?: string | null
}
// 해양 HULL 아이템 생성 데이터 타입
export interface OffshoreHullItemCreateData extends ItemCreateData {
workType: "HA" | "HE" | "HH" | "HM" | "NC"
itemList?: string | null
subItemList?: string | null
}
|