diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-05-28 00:17:56 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-05-28 00:17:56 +0000 |
| commit | 9e280704988fdeffa05c1d8cbb731722f666c6af (patch) | |
| tree | bbf57b3c882502dc7afd2ff770d95aca69fca0d9 /app/api/sync/config/route.ts | |
| parent | 44356f1b203da5169db42950a42a8146f612c674 (diff) | |
(대표님) 앱 라우터 api 파트 커밋
Diffstat (limited to 'app/api/sync/config/route.ts')
| -rw-r--r-- | app/api/sync/config/route.ts | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/app/api/sync/config/route.ts b/app/api/sync/config/route.ts new file mode 100644 index 00000000..e54762fc --- /dev/null +++ b/app/api/sync/config/route.ts @@ -0,0 +1,85 @@ +import { NextRequest, NextResponse } from "next/server" +import { syncService } from "@/lib/vendor-document-list/sync-service" +import { getServerSession } from "next-auth" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" + +export async function GET(request: NextRequest) { + try { + const { searchParams } = new URL(request.url) + const contractId = searchParams.get('contractId') + const targetSystem = searchParams.get('targetSystem') || 'SHI' + + if (!contractId) { + return NextResponse.json( + { error: 'Contract ID is required' }, + { status: 400 } + ) + } + + const config = await syncService.getSyncConfig( + parseInt(contractId), + targetSystem + ) + + // 민감한 정보 제거 + if (config) { + const { authToken, ...safeConfig } = config + return NextResponse.json({ + ...safeConfig, + hasAuthToken: !!authToken + }) + } + + return NextResponse.json(null) + } catch (error) { + console.error('Failed to get sync config:', error) + return NextResponse.json( + { error: 'Failed to get sync config' }, + { status: 500 } + ) + } +} + +export async function POST(request: NextRequest) { + try { + const session = await getServerSession(authOptions) + if (!session?.user?.id) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) + } + const body = await request.json() + const { + contractId, + targetSystem, + endpointUrl, + authToken, + syncEnabled, + syncIntervalMinutes, + maxBatchSize + } = body + + if (!contractId || !targetSystem || !endpointUrl) { + return NextResponse.json( + { error: 'Contract ID, target system, and endpoint URL are required' }, + { status: 400 } + ) + } + + await syncService.upsertSyncConfig({ + contractId, + targetSystem, + endpointUrl, + authToken, + syncEnabled, + syncIntervalMinutes, + maxBatchSize + }) + + return NextResponse.json({ success: true }) + } catch (error) { + console.error('Failed to update sync config:', error) + return NextResponse.json( + { error: 'Failed to update sync config' }, + { status: 500 } + ) + } +}
\ No newline at end of file |
