diff options
Diffstat (limited to 'lib/vendor-investigation/validations.ts')
| -rw-r--r-- | lib/vendor-investigation/validations.ts | 71 |
1 files changed, 46 insertions, 25 deletions
diff --git a/lib/vendor-investigation/validations.ts b/lib/vendor-investigation/validations.ts index 19412539..891ef178 100644 --- a/lib/vendor-investigation/validations.ts +++ b/lib/vendor-investigation/validations.ts @@ -61,24 +61,44 @@ export const searchParamsInvestigationCache = createSearchParamsCache({ export type GetVendorsInvestigationSchema = Awaited<ReturnType<typeof searchParamsInvestigationCache.parse>> // 실사 진행 관리용 스키마 -export const updateVendorInvestigationProgressSchema = z.object({ - investigationId: z.number({ - required_error: "Investigation ID is required", - }), - investigationAddress: z.string().optional(), - investigationMethod: z.enum(["PURCHASE_SELF_EVAL", "DOCUMENT_EVAL", "PRODUCT_INSPECTION", "SITE_VISIT_EVAL"]).optional(), - - // 날짜 필드들 - forecastedAt: z.union([ - z.date(), - z.string().transform((str) => str ? new Date(str) : undefined) - ]).optional(), - - confirmedAt: z.union([ - z.date(), - z.string().transform((str) => str ? new Date(str) : undefined) - ]).optional(), -}) +export const updateVendorInvestigationProgressSchema = z + .object({ + investigationId: z.number({ + required_error: "Investigation ID is required", + }), + investigationAddress: z + .string({ required_error: "실사 주소는 필수입니다." }) + .min(1, "실사 주소는 필수입니다."), + investigationMethod: z.enum([ + "PURCHASE_SELF_EVAL", + "DOCUMENT_EVAL", + "PRODUCT_INSPECTION", + "SITE_VISIT_EVAL", + ], { required_error: "실사 방법은 필수입니다." }), + + // 날짜 필드들 + forecastedAt: z.union([ + z.date(), + z.string().transform((str) => (str ? new Date(str) : undefined)), + ]), + + confirmedAt: z.union([ + z.date(), + z.string().transform((str) => (str ? new Date(str) : undefined)), + ], { required_error: "실사 계획 확정일은 필수입니다." }), + }) + .superRefine((data, ctx) => { + // 방문/제품 평가일 경우 forecastedAt은 필수 아님, 그 외에는 필수 + const method = data.investigationMethod + const requiresForecast = method !== "PRODUCT_INSPECTION" && method !== "SITE_VISIT_EVAL" + if (requiresForecast && !data.forecastedAt) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: ["forecastedAt"], + message: "실사 수행 예정일은 필수입니다.", + }) + } + }) export type UpdateVendorInvestigationProgressSchema = z.infer<typeof updateVendorInvestigationProgressSchema> @@ -87,21 +107,22 @@ export const updateVendorInvestigationResultSchema = z.object({ investigationId: z.number({ required_error: "Investigation ID is required", }), - + // 날짜 필드들 completedAt: z.union([ z.date(), z.string().transform((str) => str ? new Date(str) : undefined) - ]).optional(), - + ]), + evaluationScore: z.number() .int("평가 점수는 정수여야 합니다.") .min(0, "평가 점수는 0점 이상이어야 합니다.") - .max(100, "평가 점수는 100점 이하여야 합니다.") - .optional(), - evaluationResult: z.enum(["APPROVED", "SUPPLEMENT", "SUPPLEMENT_REINSPECT", "SUPPLEMENT_DOCUMENT", "REJECTED", "RESULT_SENT"]).optional(), + .max(100, "평가 점수는 100점 이하여야 합니다."), + evaluationResult: z.enum(["APPROVED", "SUPPLEMENT", "SUPPLEMENT_REINSPECT", "SUPPLEMENT_DOCUMENT", "REJECTED", "RESULT_SENT"]), investigationNotes: z.string().max(1000, "QM 의견은 1000자 이내로 입력해주세요.").optional(), - attachments: z.any().optional(), // File 업로드를 위한 필드 + attachments: z.any({ + required_error: "첨부파일은 필수입니다." + }), }) export type UpdateVendorInvestigationResultSchema = z.infer<typeof updateVendorInvestigationResultSchema> |
