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
|
import * as z from "zod";
import { createSearchParamsCache,
parseAsArrayOf,
parseAsInteger,
parseAsString,
parseAsStringEnum,parseAsBoolean
} from "nuqs/server"
import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
import { BasicContractTemplate, BasicContractView } from "@/db/schema";
export const basicContractTemplateSchema = z.object({
templateName: z.string().min(1, "템플릿 이름은 필수입니다."),
// 유효기간을 숫자로 변경하고 적절한 검증 추가
validityPeriod: z.coerce
.number({
required_error: "유효기간은 필수입니다.",
invalid_type_error: "유효기간은 숫자여야 합니다."
})
.int("유효기간은 정수여야 합니다.")
.min(1, "유효기간은 최소 1개월 이상이어야 합니다.")
.max(120, "유효기간은 최대 120개월(10년)을 초과할 수 없습니다.")
.default(12) // 기본값 1년(12개월)
.describe("계약 유효기간(개월)"),
status: z.enum(["ACTIVE", "INACTIVE"], {
required_error: "상태는 필수 선택사항입니다.",
invalid_type_error: "올바른 상태 값이 아닙니다."
}).default("ACTIVE"),
fileName: z.string().min(1, "파일 이름은 필수입니다."),
filePath: z.string().min(1, "파일 경로는 필수입니다."),
});
export const searchParamsTemplatesCache = createSearchParamsCache({
flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault(
[]
),
page: parseAsInteger.withDefault(1),
perPage: parseAsInteger.withDefault(10),
sort: getSortingStateParser<BasicContractTemplate>().withDefault([
{ id: "createdAt", desc: true },
]),
// advanced filter
filters: getFiltersStateParser().withDefault([]),
joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
search: parseAsString.withDefault(""),
})
export const BUSINESS_UNIT_KEYS = [
"shipBuildingApplicable",
"windApplicable",
"pcApplicable",
"nbApplicable",
"rcApplicable",
"gyApplicable",
"sysApplicable",
"infraApplicable",
] as const;
export const createBasicContractTemplateSchema = z.object({
templateName: z.string().min(1, "템플릿 이름은 필수입니다."),
legalReviewRequired: z.boolean().default(false),
// 적용 범위
shipBuildingApplicable: z.boolean().default(false),
windApplicable: z.boolean().default(false),
pcApplicable: z.boolean().default(false),
nbApplicable: z.boolean().default(false),
rcApplicable: z.boolean().default(false),
gyApplicable: z.boolean().default(false),
sysApplicable: z.boolean().default(false),
infraApplicable: z.boolean().default(false),
status: z.enum(["ACTIVE", "DISPOSED"]).default("ACTIVE"),
fileName: z.string().nullable().optional(),
filePath: z.string().nullable().optional(),
// 기존에 쓰시던 validityPeriod 를 계속 쓰실 거라면 남기고, 아니라면 지우세요.
// 예: 문자열(YYYY-MM-DD ~ YYYY-MM-DD) 또는 number(개월 수) 등 구체화 필요
validityPeriod: z.string().optional(),
}).refine((data) => {
// 최소 1개 이상 사업부 선택
return BUSINESS_UNIT_KEYS.some((k) => data[k] === true);
}, {
message: "적어도 하나의 적용 범위를 선택해야 합니다.",
path: ["shipBuildingApplicable"], // 첫 체크박스에 에러 표시 유도
});
export type CreateBasicContractTemplateSchema = z.infer<typeof createBasicContractTemplateSchema>;
export const updateBasicContractTemplateSchema = basicContractTemplateSchema.partial().extend({
id: z.number(),
});
export const deleteBasicContractTemplateSchema = z.object({
id: z.number(),
});
export type GetBasicContractTemplatesSchema = Awaited<ReturnType<typeof searchParamsTemplatesCache.parse>>
export type UpdateBasicContractTemplateSchema = z.infer<typeof updateBasicContractTemplateSchema>;
export type DeleteBasicContractTemplateSchema = z.infer<typeof deleteBasicContractTemplateSchema>;
export const searchParamsCache = createSearchParamsCache({
flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),
page: parseAsInteger.withDefault(1),
perPage: parseAsInteger.withDefault(10),
sort: getSortingStateParser<BasicContractView>().withDefault([
{ id: "createdAt", desc: true },
]),
// 고급 필터
filters: getFiltersStateParser().withDefault([]),
joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
search: parseAsString.withDefault(""),
});
export type GetBasciContractsSchema = Awaited<ReturnType<typeof searchParamsCache.parse>>;
|