diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/polices/service.ts | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/lib/polices/service.ts b/lib/polices/service.ts index 33cd592c..ce4ca26e 100644 --- a/lib/polices/service.ts +++ b/lib/polices/service.ts @@ -8,6 +8,7 @@ import { revalidatePath } from 'next/cache' // 정책 버전 생성 export async function createPolicyVersion(data: { policyType: 'privacy_policy' | 'terms_of_service' + locale: 'ko' | 'en' version: string content: string effectiveDate: Date @@ -15,17 +16,21 @@ export async function createPolicyVersion(data: { try { // 트랜잭션으로 처리 const result = await db.transaction(async (tx) => { - // 기존의 현재 정책들을 비활성화 + // 기존의 현재 정책들을 비활성화 (같은 locale, 같은 policyType) await tx .update(policyVersions) .set({ isCurrent: false }) - .where(eq(policyVersions.policyType, data.policyType)) + .where(and( + eq(policyVersions.policyType, data.policyType), + eq(policyVersions.locale, data.locale) + )) // 새 정책 버전 생성 const [newPolicy] = await tx .insert(policyVersions) .values({ policyType: data.policyType, + locale: data.locale, version: data.version, content: data.content, effectiveDate: data.effectiveDate, @@ -88,12 +93,19 @@ export async function activatePolicyVersion(policyId: number) { } // 정책 히스토리 조회 -export async function getPolicyHistory(policyType: 'privacy_policy' | 'terms_of_service') { +export async function getPolicyHistory(policyType: 'privacy_policy' | 'terms_of_service', locale?: string) { try { + const whereConditions = [eq(policyVersions.policyType, policyType)] + + // locale이 지정된 경우 해당 locale만 조회 + if (locale) { + whereConditions.push(eq(policyVersions.locale, locale)) + } + const history = await db .select() .from(policyVersions) - .where(eq(policyVersions.policyType, policyType)) + .where(and(...whereConditions)) .orderBy(desc(policyVersions.createdAt)) return { success: true, data: history } @@ -106,19 +118,29 @@ export async function getPolicyHistory(policyType: 'privacy_policy' | 'terms_of_ } } -// 현재 활성 정책들 조회 -export async function getCurrentPolicies() { +// 현재 활성 정책들 조회 (locale별) +export async function getCurrentPolicies(locale?: string) { try { + const whereConditions = [eq(policyVersions.isCurrent, true)] + + // locale이 지정된 경우 해당 locale만 조회 + if (locale) { + whereConditions.push(eq(policyVersions.locale, locale)) + } + const currentPolicies = await db .select() .from(policyVersions) - .where(eq(policyVersions.isCurrent, true)) + .where(and(...whereConditions)) - // 정책 타입별로 그룹화 + // locale별로 정책 타입별 그룹화 const grouped = currentPolicies.reduce((acc, policy) => { - acc[policy.policyType] = policy + if (!acc[policy.locale]) { + acc[policy.locale] = {} + } + acc[policy.locale][policy.policyType] = policy return acc - }, {} as Record<string, any>) + }, {} as Record<string, Record<string, any>>) return { success: true, data: grouped } } catch (error) { |
