summaryrefslogtreecommitdiff
path: root/lib/vendor-investigation/validations.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vendor-investigation/validations.ts')
-rw-r--r--lib/vendor-investigation/validations.ts56
1 files changed, 25 insertions, 31 deletions
diff --git a/lib/vendor-investigation/validations.ts b/lib/vendor-investigation/validations.ts
index 18a50022..bfe2e988 100644
--- a/lib/vendor-investigation/validations.ts
+++ b/lib/vendor-investigation/validations.ts
@@ -1,4 +1,3 @@
-import { vendorInvestigationsView } from "@/db/schema/vendors"
import {
createSearchParamsCache,
parseAsArrayOf,
@@ -8,6 +7,7 @@ import {
} from "nuqs/server"
import * as z from "zod"
import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
+import { vendorInvestigationsView } from "@/db/schema"
export const searchParamsInvestigationCache = createSearchParamsCache({
// Common flags
@@ -19,7 +19,7 @@ export const searchParamsInvestigationCache = createSearchParamsCache({
// Sorting - adjusting for vendorInvestigationsView
sort: getSortingStateParser<typeof vendorInvestigationsView.$inferSelect>().withDefault([
- { id: "investigationCreatedAt", desc: true },
+ { id: "createdAt", desc: true },
]),
// Advanced filter
@@ -60,34 +60,28 @@ export const searchParamsInvestigationCache = createSearchParamsCache({
// Finally, export the type you can use in your server action:
export type GetVendorsInvestigationSchema = Awaited<ReturnType<typeof searchParamsInvestigationCache.parse>>
-
export const updateVendorInvestigationSchema = z.object({
- investigationId: z.number(),
- investigationStatus: z.enum(["PLANNED", "IN_PROGRESS", "COMPLETED", "CANCELED"]),
-
- // If the user might send empty strings, we'll allow it by unioning with z.literal('')
- // Then transform empty string to undefined
- scheduledStartAt: z.preprocess(
- // null이나 빈 문자열을 undefined로 변환
- (val) => (val === null || val === '') ? undefined : val,
- z.date().optional()
- ),
-
- scheduledEndAt:z.preprocess(
- // null이나 빈 문자열을 undefined로 변환
- (val) => (val === null || val === '') ? undefined : val,
- z.date().optional()
- ),
-
- completedAt: z.preprocess(
- // null이나 빈 문자열을 undefined로 변환
- (val) => (val === null || val === '') ? undefined : val,
- z.date().optional()
- ),
- investigationNotes: z.string().optional(),
- attachments: z.any().optional(),
- })
+ investigationId: z.number({
+ required_error: "Investigation ID is required",
+ }),
+ investigationStatus: z.enum(["PLANNED", "IN_PROGRESS", "COMPLETED", "CANCELED"], {
+ required_error: "실사 상태를 선택해주세요.",
+ }),
+ evaluationType: z.enum(["SITE_AUDIT", "QM_SELF_AUDIT"]).optional(),
+ investigationAddress: z.string().optional(),
+ investigationMethod: z.string().max(100, "실사 방법은 100자 이내로 입력해주세요.").optional(),
+ forecastedAt: z.date().optional(),
+ requestedAt: z.date().optional(),
+ confirmedAt: z.date().optional(),
+ completedAt: z.date().optional(),
+ evaluationScore: z.number()
+ .int("평가 점수는 정수여야 합니다.")
+ .min(0, "평가 점수는 0점 이상이어야 합니다.")
+ .max(100, "평가 점수는 100점 이하여야 합니다.")
+ .optional(),
+ evaluationResult: z.enum(["APPROVED", "SUPPLEMENT", "REJECTED"]).optional(),
+ investigationNotes: z.string().max(1000, "QM 의견은 1000자 이내로 입력해주세요.").optional(),
+ attachments: z.any().optional(), // File 업로드를 위한 필드
+})
-export type UpdateVendorInvestigationSchema = z.infer<
- typeof updateVendorInvestigationSchema
-> \ No newline at end of file
+export type UpdateVendorInvestigationSchema = z.infer<typeof updateVendorInvestigationSchema>