diff options
Diffstat (limited to 'lib/approval-log/service.ts')
| -rw-r--r-- | lib/approval-log/service.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/approval-log/service.ts b/lib/approval-log/service.ts index 4d1ad7f8..5690e0f9 100644 --- a/lib/approval-log/service.ts +++ b/lib/approval-log/service.ts @@ -13,6 +13,7 @@ import { import db from '@/db/db'; import { approvalLogs } from '@/db/schema/knox/approvals'; +import { pendingActions } from '@/db/schema/knox/pending-actions'; import { filterColumns } from '@/lib/filter-columns'; // --------------------------------------------- @@ -198,3 +199,61 @@ export async function getApprovalLogListAction(input: ListInput) { }; } } + +// ---------------------------------------------------- +// Get approval log detail with pending action +// ---------------------------------------------------- +export type PendingAction = typeof pendingActions.$inferSelect; + +export interface ApprovalLogDetail { + approvalLog: ApprovalLog; + pendingAction: PendingAction | null; +} + +export async function getApprovalLogDetail(apInfId: string): Promise<ApprovalLogDetail | null> { + try { + // approvalLog 조회 + const approvalLog = await getApprovalLog(apInfId); + if (!approvalLog) { + return null; + } + + // pendingAction 조회 + const [pendingAction] = await db + .select() + .from(pendingActions) + .where(eq(pendingActions.apInfId, apInfId)) + .limit(1); + + return { + approvalLog, + pendingAction: pendingAction || null, + }; + } catch (error) { + console.error('Error fetching approval log detail:', error); + return null; + } +} + +// ---------------------------------------------------- +// Server Action for getting approval log detail +// ---------------------------------------------------- +export async function getApprovalLogDetailAction(apInfId: string) { + try { + const data = await getApprovalLogDetail(apInfId); + if (!data) { + return { + success: false, + error: '결재 로그를 찾을 수 없습니다.', + data: null, + }; + } + return { success: true, data }; + } catch (error) { + return { + success: false, + error: error instanceof Error ? error.message : '결재 로그 상세 조회에 실패했습니다.', + data: null, + }; + } +} |
