summaryrefslogtreecommitdiff
path: root/lib/notice/service.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-10-27 03:12:26 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-10-27 03:12:26 +0000
commit9f761849c2e98f650d089d00aed9df090497ada9 (patch)
treecb06b8dad5b34d1cd17997cdc82b2de5b981d965 /lib/notice/service.ts
parent94f55e3300063511c2799096128afa1b815f4f56 (diff)
(최겸) 공지사항 팝업기능 및 다시보지않기 기능 구현(로컬 스토리지 활용)
Diffstat (limited to 'lib/notice/service.ts')
-rw-r--r--lib/notice/service.ts35
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/notice/service.ts b/lib/notice/service.ts
index 9c05b98f..12f2ed2e 100644
--- a/lib/notice/service.ts
+++ b/lib/notice/service.ts
@@ -21,6 +21,23 @@ import {
import type { Notice } from "@/db/schema/notice"
+// 페이지별 공지사항 조회 (강제 모달용)
+export async function getPageNoticesForModal(pagePath: string): Promise<Array<Notice & { authorName: string | null; authorEmail: string | null }>> {
+ try {
+ console.log('🔍 Notice Service - 모달용 조회 시작:', { pagePath })
+ const result = await getNoticesByPagePath(pagePath)
+ console.log('📊 Notice Service - 모달용 조회 결과:', {
+ pagePath,
+ noticesCount: result.length,
+ notices: result.map(n => ({ id: n.id, title: n.title, pagePath: n.pagePath }))
+ })
+ return result
+ } catch (error) {
+ console.error(`Failed to get notices for modal on page ${pagePath}:`, error)
+ return []
+ }
+}
+
// 간단한 공지사항 목록 조회 (페이지네이션 없이 전체 조회)
export async function getNoticeLists(): Promise<{ data: Array<Notice & { authorName: string | null; authorEmail: string | null }> }> {
try {
@@ -33,6 +50,10 @@ export async function getNoticeLists(): Promise<{ data: Array<Notice & { authorN
content: notice.content,
authorId: notice.authorId,
isActive: notice.isActive,
+ isPopup: notice.isPopup,
+ startAt: notice.startAt,
+ endAt: notice.endAt,
+ dontShowDuration: notice.dontShowDuration,
createdAt: notice.createdAt,
updatedAt: notice.updatedAt,
authorName: users.name,
@@ -163,7 +184,19 @@ export async function deleteMultipleNotices(ids: number[]) {
// ID로 공지사항 조회
export async function getNoticeDetail(id: number): Promise<(Notice & { authorName: string | null; authorEmail: string | null }) | null> {
try {
- return await getNoticeById(id)
+ const result = await getNoticeById(id)
+ // 유효기간 검증 추가 (현재 시간이 유효기간 내에 있는지 확인)
+ if (result) {
+ const currentTime = new Date()
+ const isValid = (!result.startAt || result.startAt <= currentTime) &&
+ (!result.endAt || result.endAt >= currentTime)
+
+ if (!isValid) {
+ console.log(`Notice ${id} is not in valid time range`)
+ return null
+ }
+ }
+ return result
} catch (error) {
console.error(`Failed to get notice detail for id ${id}:`, error)
return null