diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-25 07:51:15 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-25 07:51:15 +0000 |
| commit | 2650b7c0bb0ea12b68a58c0439f72d61df04b2f1 (patch) | |
| tree | 17156183fd74b69d78178065388ac61a18ac07b4 /lib/gtc-contract/validations.ts | |
| parent | d32acea05915bd6c1ed4b95e56c41ef9204347bc (diff) | |
(대표님) 정기평가 대상, 미들웨어 수정, nextauth 토큰 처리 개선, GTC 등
(최겸) 기술영업
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({ |
