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
|
import {
createSearchParamsCache,
parseAsArrayOf,
parseAsInteger,
parseAsString,
parseAsStringEnum,
} from "nuqs/server"
import * as z from "zod"
import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
import { ProcurementItem } 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<ProcurementItem>().withDefault([
{ id: "createdAt", desc: true },
]),
itemCode: parseAsString.withDefault(""),
itemName: parseAsString.withDefault(""),
material: parseAsString.withDefault(""),
specification: parseAsString.withDefault(""),
unit: parseAsString.withDefault(""),
isActive: parseAsString.withDefault(""),
// advanced filter
filters: getFiltersStateParser().withDefault([]),
joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
search: parseAsString.withDefault(""),
})
export type GetProcurementItemsSchema = Awaited<ReturnType<typeof searchParamsCache.parse>>
export const createProcurementItemSchema = z.object({
itemCode: z.string().min(1, "품목코드는 필수입니다"),
itemName: z.string().min(1, "품목명은 필수입니다"),
material: z.string().max(100).optional().or(z.literal("")),
specification: z.string().max(255).optional().or(z.literal("")),
unit: z.string().max(50).optional().or(z.literal("")),
isActive: z.string().max(1).default('Y').optional(),
})
export type CreateProcurementItemSchema = z.infer<typeof createProcurementItemSchema>
export const updateProcurementItemSchema = z.object({
itemCode: z.string().optional(),
itemName: z.string().optional(),
material: z.string().max(100).optional(),
specification: z.string().max(255).optional(),
unit: z.string().max(50).optional(),
isActive: z.string().max(1).optional(),
})
export type UpdateProcurementItemSchema = z.infer<typeof updateProcurementItemSchema>
|