diff options
Diffstat (limited to 'lib/gtc-contract/validations.ts')
| -rw-r--r-- | lib/gtc-contract/validations.ts | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/lib/gtc-contract/validations.ts b/lib/gtc-contract/validations.ts index b79a8b08..671e25b7 100644 --- a/lib/gtc-contract/validations.ts +++ b/lib/gtc-contract/validations.ts @@ -8,7 +8,6 @@ import { } from "nuqs/server" import * as z from "zod" import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers" -import { checkProjectExists } from "./service" export const searchParamsCache = createSearchParamsCache({ flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault( @@ -30,47 +29,30 @@ export const searchParamsCache = createSearchParamsCache({ export const createGtcDocumentSchema = z.object({ type: z.enum(["standard", "project"]), - projectId: z - .number() - .nullable() - .optional() - .refine( - async (projectId, ctx) => { - // 프로젝트 타입인 경우 projectId 필수 - if (ctx.parent.type === "project" && !projectId) { - ctx.addIssue({ - code: z.ZodIssueCode.custom, - message: "Project is required for project type GTC", - }) - return false - } - - // 표준 타입인 경우 projectId null이어야 함 - if (ctx.parent.type === "standard" && projectId) { - ctx.addIssue({ - code: z.ZodIssueCode.custom, - message: "Project should not be set for standard type GTC", - }) - return false - } - - // 프로젝트 ID가 유효한지 검사 - if (projectId) { - const exists = await checkProjectExists(projectId) - if (!exists) { - ctx.addIssue({ - code: z.ZodIssueCode.custom, - message: "Invalid project ID", - }) - return false - } - } - - return true - } - ), + projectId: z.number().nullable().optional(), revision: z.number().min(0).default(0), editReason: z.string().optional(), +}).superRefine(async (data, ctx) => { + // 프로젝트 타입인 경우 projectId 필수 + if (data.type === "project" && !data.projectId) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: "Project is required for project type GTC", + path: ["projectId"], + }) + return + } + + // 표준 타입인 경우 projectId null이어야 함 + if (data.type === "standard" && data.projectId) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: "Project should not be set for standard type GTC", + path: ["projectId"], + }) + return + } + }) export const updateGtcDocumentSchema = z.object({ |
