diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-04-28 02:13:30 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-04-28 02:13:30 +0000 |
| commit | ef4c533ebacc2cdc97e518f30e9a9350004fcdfb (patch) | |
| tree | 345251a3ed0f4429716fa5edaa31024d8f4cb560 /lib/vendor-candidates/validations.ts | |
| parent | 9ceed79cf32c896f8a998399bf1b296506b2cd4a (diff) | |
~20250428 작업사항
Diffstat (limited to 'lib/vendor-candidates/validations.ts')
| -rw-r--r-- | lib/vendor-candidates/validations.ts | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/lib/vendor-candidates/validations.ts b/lib/vendor-candidates/validations.ts index 0abb568e..f42d4d3f 100644 --- a/lib/vendor-candidates/validations.ts +++ b/lib/vendor-candidates/validations.ts @@ -1,4 +1,4 @@ -import { vendorCandidates } from "@/db/schema/vendors" +import { vendorCandidates, vendorCandidatesWithVendorInfo } from "@/db/schema/vendors" import { createSearchParamsCache, parseAsArrayOf, @@ -12,13 +12,14 @@ import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers" export const searchParamsCandidateCache = createSearchParamsCache({ // Common flags flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]), - + from: parseAsString.withDefault(""), + to: parseAsString.withDefault(""), // Paging page: parseAsInteger.withDefault(1), perPage: parseAsInteger.withDefault(10), // Sorting - adjusting for vendorInvestigationsView - sort: getSortingStateParser<typeof vendorCandidates.$inferSelect>().withDefault([ + sort: getSortingStateParser<typeof vendorCandidatesWithVendorInfo.$inferSelect>().withDefault([ { id: "createdAt", desc: true }, ]), @@ -53,22 +54,45 @@ export type GetVendorsCandidateSchema = Awaited<ReturnType<typeof searchParamsCa // Updated version of the updateVendorCandidateSchema export const updateVendorCandidateSchema = z.object({ id: z.number(), - companyName: z.string().min(1).max(255).optional(), - contactEmail: z.string().email().max(255).optional(), - contactPhone: z.string().max(50).optional(), - country: z.string().max(100).optional(), - source: z.string().max(100).optional(), - status: z.enum(["COLLECTED", "INVITED", "DISCARDED"]).optional(), + // 필수 필드 + companyName: z.string().min(1, "회사명은 필수입니다").max(255), + // null을 명시적으로 처리 + contactEmail: z.union([ + z.string().email("유효한 이메일 형식이 아닙니다").max(255), + z.literal(''), + z.null() + ]).optional().transform(val => val === null ? '' : val), + contactPhone: z.union([z.string().max(50), z.literal(''), z.null()]).optional() + .transform(val => val === null ? '' : val), + country: z.union([z.string().max(100), z.literal(''), z.null()]).optional() + .transform(val => val === null ? '' : val), + // 필수 필드 + source: z.string().min(1, "출처는 필수입니다").max(100), + address: z.union([z.string(), z.literal(''), z.null()]).optional() + .transform(val => val === null ? '' : val), + taxId: z.union([z.string(), z.literal(''), z.null()]).optional() + .transform(val => val === null ? '' : val), + // 필수 필드 + items: z.string().min(1, "항목은 필수입니다"), + remark: z.union([z.string(), z.literal(''), z.null()]).optional() + .transform(val => val === null ? '' : val), + status: z.enum(["COLLECTED", "INVITED", "DISCARDED"]), updatedAt: z.date().optional().default(() => new Date()), -}); +});; // Create schema for vendor candidates export const createVendorCandidateSchema = z.object({ - companyName: z.string().min(1).max(255), - contactEmail: z.string().email().max(255), + companyName: z.string().min(1, "회사명은 필수입니다").max(255), + // 빈 문자열을 undefined로 변환하여 optional 처리 + contactEmail: z.string().email("유효한 이메일 형식이 아닙니다").or(z.literal('')).optional(), contactPhone: z.string().max(50).optional(), country: z.string().max(100).optional(), - source: z.string().max(100).optional(), + source: z.string().min(1, "출처는 필수입니다").max(100), + address: z.string().optional(), + taxId: z.string().optional(), + items: z.string().min(1, "항목은 필수입니다"), + remark: z.string().optional(), + vendorId: z.number().optional(), status: z.enum(["COLLECTED", "INVITED", "DISCARDED"]).default("COLLECTED"), }); |
