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-type/validations.ts | |
| parent | 9ceed79cf32c896f8a998399bf1b296506b2cd4a (diff) | |
~20250428 작업사항
Diffstat (limited to 'lib/vendor-type/validations.ts')
| -rw-r--r-- | lib/vendor-type/validations.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/vendor-type/validations.ts b/lib/vendor-type/validations.ts new file mode 100644 index 00000000..146c404e --- /dev/null +++ b/lib/vendor-type/validations.ts @@ -0,0 +1,46 @@ +import { + createSearchParamsCache, + parseAsArrayOf, + parseAsInteger, + parseAsString, + parseAsStringEnum, +} from "nuqs/server" +import * as z from "zod" + +import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers" +import { VendorTypes } from "@/db/schema" + +export const searchParamsCache = createSearchParamsCache({ + flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault( + [] + ), + page: parseAsInteger.withDefault(1), + perPage: parseAsInteger.withDefault(10), + sort: getSortingStateParser<VendorTypes>().withDefault([ + { id: "createdAt", desc: true }, + ]), + nameKo: parseAsString.withDefault(""), + nameEn: parseAsString.withDefault(""), + from: parseAsString.withDefault(""), + to: parseAsString.withDefault(""), + // advanced filter + filters: getFiltersStateParser().withDefault([]), + joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), + search: parseAsString.withDefault(""), + +}) + +export const createVendorTypeSchema = z.object({ + nameKo: z.string(), + nameEn: z.string(), + +}) + +export const updateVendorTypeSchema = z.object({ + nameKo: z.string().optional(), + nameEn: z.string().optional(), +}) + +export type GetVendorTypesSchema = Awaited<ReturnType<typeof searchParamsCache.parse>> +export type CreateVendorTypeSchema = z.infer<typeof createVendorTypeSchema> +export type UpdateVendorTypeSchema = z.infer<typeof updateVendorTypeSchema> |
