summaryrefslogtreecommitdiff
path: root/lib/vendor-candidates/validations.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-04-02 09:54:08 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-04-02 09:54:08 +0000
commitdfdfae3018f8499240f48d28ce634f4a5c56e006 (patch)
tree4493b172c061fa5bf4e94c083788110eb1507f6d /lib/vendor-candidates/validations.ts
parent21a72eeddc74cf775e2a76e2c569de970bd62a7f (diff)
벤더 코멘트 처리
Diffstat (limited to 'lib/vendor-candidates/validations.ts')
-rw-r--r--lib/vendor-candidates/validations.ts84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/vendor-candidates/validations.ts b/lib/vendor-candidates/validations.ts
new file mode 100644
index 00000000..0abb568e
--- /dev/null
+++ b/lib/vendor-candidates/validations.ts
@@ -0,0 +1,84 @@
+import { vendorCandidates } 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 searchParamsCandidateCache = 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 vendorCandidates.$inferSelect>().withDefault([
+ { id: "createdAt", 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
+ status: parseAsStringEnum(["COLLECTED", "INVITED", "DISCARDED"]),
+
+ // In case you also want to filter by vendorName, vendorCode, etc.
+ companyName: parseAsString.withDefault(""),
+ contactEmail: parseAsString.withDefault(""),
+ contactPhone: parseAsString.withDefault(""),
+ country: parseAsString.withDefault(""),
+ source: parseAsString.withDefault(""),
+
+
+})
+
+// Finally, export the type you can use in your server action:
+export type GetVendorsCandidateSchema = Awaited<ReturnType<typeof searchParamsCandidateCache.parse>>
+
+
+// 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(),
+ 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),
+ contactPhone: z.string().max(50).optional(),
+ country: z.string().max(100).optional(),
+ source: z.string().max(100).optional(),
+ status: z.enum(["COLLECTED", "INVITED", "DISCARDED"]).default("COLLECTED"),
+});
+
+// Export types for both schemas
+export type UpdateVendorCandidateSchema = z.infer<typeof updateVendorCandidateSchema>;
+export type CreateVendorCandidateSchema = z.infer<typeof createVendorCandidateSchema>;
+
+
+export const removeCandidatesSchema = z.object({
+ ids: z.array(z.number()).min(1, "At least one candidate ID must be provided"),
+});
+
+export type RemoveCandidatesInput = z.infer<typeof removeCandidatesSchema>; \ No newline at end of file