32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
|
|
'use server';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 공지 팝업 서버 액션
|
||
|
|
*
|
||
|
|
* API Endpoints:
|
||
|
|
* - GET /api/v1/popups/active - 사용자용 활성 팝업 조회 (날짜+부서 필터 백엔드 처리)
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { executeServerAction } from '@/lib/api/execute-server-action';
|
||
|
|
import { buildApiUrl } from '@/lib/api/query-params';
|
||
|
|
import { type PopupApiData, transformApiToFrontend } from '@/components/settings/PopupManagement/utils';
|
||
|
|
import type { Popup } from '@/components/settings/PopupManagement/types';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 활성 팝업 목록 조회 (사용자용)
|
||
|
|
* - 백엔드 scopeActive(): status=active + 날짜 범위 내
|
||
|
|
* - 백엔드 scopeForUser(): 전사 OR 사용자 부서
|
||
|
|
* @param departmentId - 사용자 소속 부서 ID (부서별 팝업 필터용)
|
||
|
|
*/
|
||
|
|
export async function getActivePopups(departmentId?: number): Promise<Popup[]> {
|
||
|
|
const result = await executeServerAction({
|
||
|
|
url: buildApiUrl('/api/v1/popups/active', {
|
||
|
|
department_id: departmentId,
|
||
|
|
}),
|
||
|
|
transform: (data: PopupApiData[]) => data.map(transformApiToFrontend),
|
||
|
|
errorMessage: '활성 팝업 조회에 실패했습니다.',
|
||
|
|
});
|
||
|
|
|
||
|
|
return result.success ? (result.data ?? []) : [];
|
||
|
|
}
|