summaryrefslogtreecommitdiff
path: root/lib/information/service.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-08-22 02:12:15 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-08-22 02:12:15 +0000
commit7dd2b9fc1856306652f311d19697d9880955bfab (patch)
tree3144f14e2b6e9d66c25f10686ca9e94d61d9154e /lib/information/service.ts
parent94082bfe915d3b0337f8929a2bb27828abb5d3c7 (diff)
(최겸) 공지사항, 인포메이션 기능 수정
Diffstat (limited to 'lib/information/service.ts')
-rw-r--r--lib/information/service.ts74
1 files changed, 40 insertions, 34 deletions
diff --git a/lib/information/service.ts b/lib/information/service.ts
index 2826c0e9..2d3ad079 100644
--- a/lib/information/service.ts
+++ b/lib/information/service.ts
@@ -1,8 +1,6 @@
"use server"
-import { revalidateTag } from "next/cache"
import { getErrorMessage } from "@/lib/handle-error"
-import { unstable_cache } from "@/lib/unstable-cache"
import { desc, or, eq } from "drizzle-orm"
import db from "@/db/db"
import { pageInformation, menuAssignments } from "@/db/schema"
@@ -45,22 +43,29 @@ export async function getInformationLists() {
// 페이지별 인포메이션 조회 (첨부파일 포함)
export async function getPageInformation(pagePath: string) {
try {
- return await getInformationByPagePathWithAttachments(pagePath)
+ console.log('🔍 Information Service - 조회 시작:', { pagePath })
+ const result = await getInformationByPagePathWithAttachments(pagePath)
+ console.log('📊 Information Service - 조회 결과:', {
+ pagePath,
+ found: !!result,
+ resultData: result ? {
+ id: result.id,
+ pagePath: result.pagePath,
+ pageName: result.pageName,
+ attachmentsCount: result.attachments?.length || 0
+ } : null
+ })
+ return result
} catch (error) {
console.error(`Failed to get information for page ${pagePath}:`, error)
return null
}
}
-// 캐시된 페이지별 인포메이션 조회
-export const getCachedPageInformation = unstable_cache(
- async (pagePath: string) => getPageInformation(pagePath),
- ["page-information"],
- {
- tags: ["page-information"],
- revalidate: 3600, // 1시간 캐시
- }
-)
+// 페이지별 인포메이션 조회 (직접 호출용)
+export async function getPageInformationDirect(pagePath: string) {
+ return await getPageInformation(pagePath)
+}
// 인포메이션 수정 (내용과 첨부파일만)
export async function updateInformationData(input: UpdateInformationSchema) {
@@ -83,9 +88,7 @@ export async function updateInformationData(input: UpdateInformationSchema) {
}
}
- revalidateTag("page-information")
- revalidateTag("information-lists")
- revalidateTag("information-edit-permission") // 편집 권한 캐시 무효화
+ // 캐시 무효화 제거됨
return {
success: true,
@@ -113,13 +116,18 @@ export async function getInformationDetail(id: number) {
// 인포메이션 편집 권한 확인
export async function checkInformationEditPermission(pagePath: string, userId: string): Promise<boolean> {
try {
+ // pagePath 정규화 (앞의 / 제거)
+ const normalizedPagePath = pagePath.startsWith('/') ? pagePath.slice(1) : pagePath
+
// pagePath를 menuPath로 변환 (pagePath가 menuPath의 마지막 부분이라고 가정)
// 예: pagePath "vendor-list" -> menuPath "/evcp/vendor-list" 또는 "/partners/vendor-list"
const menuPathQueries = [
- `/evcp/${pagePath}`,
- `/partners/${pagePath}`,
- `/${pagePath}`, // 루트 경로
- pagePath // 정확한 매칭
+ `/evcp/${normalizedPagePath}`,
+ `/partners/${normalizedPagePath}`,
+ `/${normalizedPagePath}`, // 루트 경로
+ normalizedPagePath, // 정확한 매칭
+ `/${pagePath}`, // 원본 경로도 체크
+ pagePath // 원본 경로 정확한 매칭
]
// menu_assignments에서 해당 pagePath와 매칭되는 메뉴 찾기
@@ -149,15 +157,10 @@ export async function checkInformationEditPermission(pagePath: string, userId: s
}
}
-// 캐시된 권한 확인
-export const getCachedEditPermission = unstable_cache(
- async (pagePath: string, userId: string) => checkInformationEditPermission(pagePath, userId),
- ["information-edit-permission"],
- {
- tags: ["information-edit-permission"],
- revalidate: 300, // 5분 캐시
- }
-)
+// 권한 확인 (직접 호출용)
+export async function getEditPermissionDirect(pagePath: string, userId: string) {
+ return await checkInformationEditPermission(pagePath, userId)
+}
// menu_assignments 기반으로 page_information 동기화
export async function syncInformationFromMenuAssignments() {
@@ -170,9 +173,14 @@ export async function syncInformationFromMenuAssignments() {
// upsert를 사용하여 각 메뉴 항목 처리
for (const menu of menuItems) {
try {
+ // 맨 앞의 / 제거하여 pagePath 정규화
+ const normalizedPagePath = menu.menuPath.startsWith('/')
+ ? menu.menuPath.slice(1)
+ : menu.menuPath;
+
await db.insert(pageInformation)
.values({
- pagePath: menu.menuPath,
+ pagePath: normalizedPagePath,
pageName: menu.menuTitle,
informationContent: "",
isActive: true // 기본값으로 활성화
@@ -191,7 +199,7 @@ export async function syncInformationFromMenuAssignments() {
}
}
- revalidateTag("information");
+ // 캐시 무효화 제거됨
return {
success: true,
@@ -249,8 +257,7 @@ export async function uploadInformationAttachment(formData: FormData) {
}
}
- revalidateTag("page-information")
- revalidateTag("information-lists")
+ // 캐시 무효화 제거됨
return {
success: true,
@@ -288,8 +295,7 @@ export async function deleteInformationAttachmentAction(attachmentId: number) {
}
}
- revalidateTag("page-information")
- revalidateTag("information-lists")
+ // 캐시 무효화 제거됨
return {
success: true,