summaryrefslogtreecommitdiff
path: root/lib/notice/repository.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/notice/repository.ts')
-rw-r--r--lib/notice/repository.ts23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/notice/repository.ts b/lib/notice/repository.ts
index fb941ac9..897eb5b0 100644
--- a/lib/notice/repository.ts
+++ b/lib/notice/repository.ts
@@ -2,8 +2,10 @@ import { desc, eq, and, sql } from "drizzle-orm"
import db from "@/db/db"
import { notice, users, type Notice, type NewNotice } from "@/db/schema"
-// 페이지 경로별 공지사항 조회 (활성화된 것만, 작성자 정보 포함)
+// 페이지 경로별 공지사항 조회 (활성화된 것만, 작성자 정보 포함, 유효기간 내 공지사항만)
export async function getNoticesByPagePath(pagePath: string): Promise<Array<Notice & { authorName: string | null; authorEmail: string | null }>> {
+ const currentTime = new Date()
+
const result = await db
.select({
id: notice.id,
@@ -12,6 +14,10 @@ export async function getNoticesByPagePath(pagePath: string): Promise<Array<Noti
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,
@@ -21,7 +27,10 @@ export async function getNoticesByPagePath(pagePath: string): Promise<Array<Noti
.leftJoin(users, eq(notice.authorId, users.id))
.where(and(
eq(notice.pagePath, pagePath),
- eq(notice.isActive, true)
+ eq(notice.isActive, true),
+ // // 유효기간 필터링: startAt과 endAt이 모두 null이거나 현재 시간이 범위 내에 있어야 함
+ // sql`(${notice.startAt} IS NULL OR ${notice.startAt} <= ${currentTime})`,
+ // sql`(${notice.endAt} IS NULL OR ${notice.endAt} >= ${currentTime})`
))
.orderBy(desc(notice.createdAt))
@@ -32,7 +41,11 @@ export async function getNoticesByPagePath(pagePath: string): Promise<Array<Noti
export async function insertNotice(data: NewNotice): Promise<Notice> {
const result = await db
.insert(notice)
- .values(data)
+ .values({
+ ...data,
+ createdAt: new Date(),
+ updatedAt: new Date()
+ })
.returning()
return result[0]
@@ -77,6 +90,10 @@ export async function getNoticeById(id: number): Promise<(Notice & { authorName:
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,