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 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 { projectId, targetSystem = 'SHI' } = body if (!projectId) { return NextResponse.json( { error: 'Contract ID is required' }, { status: 400 } ) } const result = await syncService.syncToExternalSystem( projectId, targetSystem, true // manual trigger ) return NextResponse.json(result) } catch (error) { console.error('Sync trigger failed:', error) return NextResponse.json( { error: 'Sync failed', message: error instanceof Error ? error.message : 'Unknown error' }, { status: 500 } ) } }