diff options
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 |
