diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-03-26 00:37:41 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-03-26 00:37:41 +0000 |
| commit | e0dfb55c5457aec489fc084c4567e791b4c65eb1 (patch) | |
| tree | 68543a65d88f5afb3a0202925804103daa91bc6f /lib/items/validations.ts | |
3/25 까지의 대표님 작업사항
Diffstat (limited to 'lib/items/validations.ts')
| -rw-r--r-- | lib/items/validations.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/items/validations.ts b/lib/items/validations.ts new file mode 100644 index 00000000..d299959c --- /dev/null +++ b/lib/items/validations.ts @@ -0,0 +1,47 @@ +import { + createSearchParamsCache, + parseAsArrayOf, + parseAsInteger, + parseAsString, + parseAsStringEnum, +} from "nuqs/server" +import * as z from "zod" + +import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers" +import { Item } from "@/db/schema/items"; + +export const searchParamsCache = createSearchParamsCache({ + flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault( + [] + ), + page: parseAsInteger.withDefault(1), + perPage: parseAsInteger.withDefault(10), + sort: getSortingStateParser<Item>().withDefault([ + { id: "createdAt", desc: true }, + ]), + itemCode: parseAsString.withDefault(""), + itemName: parseAsString.withDefault(""), + description: parseAsString.withDefault(""), + + // advanced filter + filters: getFiltersStateParser().withDefault([]), + joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), + search: parseAsString.withDefault(""), + +}) + +export const createItemSchema = z.object({ + itemCode: z.string(), + itemName: z.string(), + description: z.string(), +}) + +export const updateItemSchema = z.object({ + itemCode: z.string().optional(), + itemName: z.string().optional(), + description: z.string().optional(), +}) + +export type GetItemsSchema = Awaited<ReturnType<typeof searchParamsCache.parse>> +export type CreateItemSchema = z.infer<typeof createItemSchema> +export type UpdateItemSchema = z.infer<typeof updateItemSchema> |
