summaryrefslogtreecommitdiff
path: root/lib/notice/validations.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-07-01 11:46:33 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-07-01 11:46:33 +0000
commit795b4915069c44f500a91638e16ded67b9e16618 (patch)
tree6306adceb723a08391af6f968fee25ef4f66446a /lib/notice/validations.ts
parenta382208003044caa45bb1cecb67dade544d44ada (diff)
(최겸) 정보시스템 공지사항 개발
Diffstat (limited to 'lib/notice/validations.ts')
-rw-r--r--lib/notice/validations.ts80
1 files changed, 80 insertions, 0 deletions
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<Notice>().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<typeof createNoticeSchema>
+export type UpdateNoticeSchema = z.infer<typeof updateNoticeSchema>
+export type GetNoticeSchema = Awaited<ReturnType<typeof searchParamsNoticeCache.parse>>
+
+// 기존 스키마 (하위 호환성을 위해 유지)
+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<typeof getPageNoticeSchema> \ No newline at end of file