diff options
Diffstat (limited to 'lib/notice/service.ts')
| -rw-r--r-- | lib/notice/service.ts | 35 |
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
|
