diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-04-02 09:54:08 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-04-02 09:54:08 +0000 |
| commit | dfdfae3018f8499240f48d28ce634f4a5c56e006 (patch) | |
| tree | 4493b172c061fa5bf4e94c083788110eb1507f6d /lib/vendor-investigation/validations.ts | |
| parent | 21a72eeddc74cf775e2a76e2c569de970bd62a7f (diff) | |
벤더 코멘트 처리
Diffstat (limited to 'lib/vendor-investigation/validations.ts')
| -rw-r--r-- | lib/vendor-investigation/validations.ts | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/lib/vendor-investigation/validations.ts b/lib/vendor-investigation/validations.ts new file mode 100644 index 00000000..18a50022 --- /dev/null +++ b/lib/vendor-investigation/validations.ts @@ -0,0 +1,93 @@ +import { vendorInvestigationsView } from "@/db/schema/vendors" +import { + createSearchParamsCache, + parseAsArrayOf, + parseAsInteger, + parseAsString, + parseAsStringEnum, +} from "nuqs/server" +import * as z from "zod" +import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers" + +export const searchParamsInvestigationCache = createSearchParamsCache({ + // Common flags + flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]), + + // Paging + page: parseAsInteger.withDefault(1), + perPage: parseAsInteger.withDefault(10), + + // Sorting - adjusting for vendorInvestigationsView + sort: getSortingStateParser<typeof vendorInvestigationsView.$inferSelect>().withDefault([ + { id: "investigationCreatedAt", desc: true }, + ]), + + // Advanced filter + filters: getFiltersStateParser().withDefault([]), + joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), + + // Global search + search: parseAsString.withDefault(""), + + // ----------------------------------------------------------------- + // Fields specific to vendor investigations + // ----------------------------------------------------------------- + + // investigationStatus: PLANNED, IN_PROGRESS, COMPLETED, CANCELED + investigationStatus: parseAsStringEnum(["PLANNED", "IN_PROGRESS", "COMPLETED", "CANCELED"]), + + // In case you also want to filter by vendorName, vendorCode, etc. + vendorName: parseAsString.withDefault(""), + vendorCode: parseAsString.withDefault(""), + + // If you need to filter by vendor status (e.g., PQ_SUBMITTED, ACTIVE, etc.), + // you can include it here too. Example: + // vendorStatus: parseAsStringEnum([ + // "PENDING_REVIEW", + // "IN_REVIEW", + // "REJECTED", + // "IN_PQ", + // "PQ_SUBMITTED", + // "PQ_FAILED", + // "PQ_APPROVED", + // "APPROVED", + // "ACTIVE", + // "INACTIVE", + // "BLACKLISTED", + // ]).optional(), +}) + +// 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(), + }) + +export type UpdateVendorInvestigationSchema = z.infer< + typeof updateVendorInvestigationSchema +>
\ No newline at end of file |
