From 795b4915069c44f500a91638e16ded67b9e16618 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Tue, 1 Jul 2025 11:46:33 +0000 Subject: (최겸) 정보시스템 공지사항 개발 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notice/validations.ts | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/notice/validations.ts (limited to 'lib/notice/validations.ts') diff --git a/lib/notice/validations.ts b/lib/notice/validations.ts new file mode 100644 index 00000000..05e84af9 --- /dev/null +++ b/lib/notice/validations.ts @@ -0,0 +1,80 @@ +import { z } from "zod" +import { + createSearchParamsCache, + parseAsArrayOf, + parseAsInteger, + parseAsString, + parseAsStringEnum, + parseAsBoolean, +} from "nuqs/server" +import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers" +import { Notice } from "@/db/schema/notice" + +// 공지사항 생성 스키마 +export const createNoticeSchema = z.object({ + pagePath: z.string().min(1, "페이지 경로를 입력해주세요"), + title: z.string().min(1, "제목을 입력해주세요"), + content: z.string().min(1, "내용을 입력해주세요"), + authorId: z.number().min(1, "작성자를 선택해주세요"), + isActive: z.boolean().default(true), +}) + +// 공지사항 수정 스키마 +export const updateNoticeSchema = z.object({ + id: z.number(), + pagePath: z.string().min(1, "페이지 경로를 입력해주세요"), + title: z.string().min(1, "제목을 입력해주세요"), + content: z.string().min(1, "내용을 입력해주세요"), + isActive: z.boolean().default(true), +}) + +// 현대적인 검색 파라미터 캐시 +export const searchParamsNoticeCache = createSearchParamsCache({ + flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]), + page: parseAsInteger.withDefault(1), + perPage: parseAsInteger.withDefault(10), + sort: getSortingStateParser().withDefault([ + { id: "createdAt", desc: true }, + ]), + + // 기본 검색 필드들 + pagePath: parseAsString.withDefault(""), + title: parseAsString.withDefault(""), + content: parseAsString.withDefault(""), + authorId: parseAsInteger, + isActive: parseAsBoolean, + + // 고급 필터 + filters: getFiltersStateParser().withDefault([]), + joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), + search: parseAsString.withDefault(""), + + // 날짜 범위 + from: parseAsString.withDefault(""), + to: parseAsString.withDefault(""), +}) + +// 타입 추출 +export type CreateNoticeSchema = z.infer +export type UpdateNoticeSchema = z.infer +export type GetNoticeSchema = Awaited> + +// 기존 스키마 (하위 호환성을 위해 유지) +export const getNoticeSchema = z.object({ + page: z.coerce.number().default(1), + per_page: z.coerce.number().default(10), + sort: z.string().optional(), + pagePath: z.string().optional(), + title: z.string().optional(), + authorId: z.coerce.number().optional(), + isActive: z.coerce.boolean().optional(), + from: z.string().optional(), + to: z.string().optional(), +}) + +// 페이지 경로별 공지사항 조회 스키마 +export const getPageNoticeSchema = z.object({ + pagePath: z.string().min(1, "페이지 경로를 입력해주세요"), +}) + +export type GetPageNoticeSchema = z.infer \ No newline at end of file -- cgit v1.2.3