From d0d2eaa2de58a0c33e9a21604b126961403cd69e Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 14 May 2025 06:12:13 +0000 Subject: (최겸) 기술영업 조선, 해양Top, 해양 Hull 아이템 리스트 개발(CRUD, excel import/export/template) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/items-tech/validations.ts | 156 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 lib/items-tech/validations.ts (limited to 'lib/items-tech/validations.ts') diff --git a/lib/items-tech/validations.ts b/lib/items-tech/validations.ts new file mode 100644 index 00000000..7c8a58f9 --- /dev/null +++ b/lib/items-tech/validations.ts @@ -0,0 +1,156 @@ +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().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().nullish(), +}) + +// 조선 아이템 업데이트 스키마 +export const updateShipbuildingItemSchema = z.object({ + itemCode: z.string(), + itemName: z.string().optional(), + description: z.string().optional(), + workType: z.string().optional(), + shipTypes: z.string().optional(), +}) + +export type GetItemsSchema = Awaited> +export type CreateItemSchema = z.infer +export type UpdateItemSchema = z.infer +export type UpdateShipbuildingItemSchema = z.infer + +// 조선 아이템 스키마 +export const createShipbuildingItemSchema = z.object({ + itemCode: z.string(), + itemName: z.string(), + description: z.string(), + workType: z.string(), + shipTypes: z.string(), +}) + +export type CreateShipbuildingItemSchema = z.infer + +// 기본 아이템 생성 데이터 타입 +export interface ItemCreateData { + itemCode: string + itemName: string + description: string | null +} + +// 조선 아이템 생성 데이터 타입 +export interface ShipbuildingItemCreateData extends ItemCreateData { + workType: string | null + shipTypes: string | null +} + +// 아이템 타입에 따른 생성 데이터 타입 +export type TypedItemCreateData = ShipbuildingItemCreateData + +// 해양 TOP 아이템 스키마 +export const createOffshoreTopItemSchema = z.object({ + itemCode: z.string(), + itemName: z.string(), + description: z.string(), + workType: z.enum(["TM", "TS", "TE", "TP"]), + itemList1: z.string().optional(), + itemList2: z.string().optional(), + itemList3: z.string().optional(), + itemList4: z.string().optional(), +}) + +// 해양 HULL 아이템 스키마 +export const createOffshoreHullItemSchema = z.object({ + itemCode: z.string(), + itemName: z.string(), + description: z.string(), + workType: z.enum(["HA", "HE", "HH", "HM", "NC"]), + itemList1: z.string().optional(), + itemList2: z.string().optional(), + itemList3: z.string().optional(), + itemList4: z.string().optional(), +}) + +export type CreateOffshoreTopItemSchema = z.infer +export type CreateOffshoreHullItemSchema = z.infer + +// 해양 TOP 아이템 업데이트 스키마 +export const updateOffshoreTopItemSchema = z.object({ + itemCode: z.string(), + itemName: z.string().optional(), + description: z.string().optional(), + workType: z.enum(["TM", "TS", "TE", "TP"]).optional(), + itemList1: z.string().optional(), + itemList2: z.string().optional(), + itemList3: z.string().optional(), + itemList4: z.string().optional(), +}) + +// 해양 HULL 아이템 업데이트 스키마 +export const updateOffshoreHullItemSchema = z.object({ + itemCode: z.string(), + itemName: z.string().optional(), + description: z.string().optional(), + workType: z.enum(["HA", "HE", "HH", "HM", "NC"]).optional(), + itemList1: z.string().optional(), + itemList2: z.string().optional(), + itemList3: z.string().optional(), + itemList4: z.string().optional(), +}) + +export type UpdateOffshoreTopItemSchema = z.infer +export type UpdateOffshoreHullItemSchema = z.infer + +// 해양 TOP 아이템 생성 데이터 타입 +export interface OffshoreTopItemCreateData extends ItemCreateData { + workType: "TM" | "TS" | "TE" | "TP" + itemList1?: string | null + itemList2?: string | null + itemList3?: string | null + itemList4?: string | null +} + +// 해양 HULL 아이템 생성 데이터 타입 +export interface OffshoreHullItemCreateData extends ItemCreateData { + workType: "HA" | "HE" | "HH" | "HM" | "NC" + itemList1?: string | null + itemList2?: string | null + itemList3?: string | null + itemList4?: string | null +} + -- cgit v1.2.3