1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// app/api/sync/import/status/route.ts
import { NextRequest, NextResponse } from "next/server"
import { importService } from "@/lib/vendor-document-list/import-service"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/api/auth/[...nextauth]/route"
import { debugProcess, debugError, debugSuccess } from "@/lib/debug-utils"
export async function GET(request: NextRequest) {
try {
const session = await getServerSession(authOptions)
if (!session?.user?.id) {
debugError(`인증 실패`, { userId: session?.user?.id })
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
}
const { searchParams } = new URL(request.url)
// 프로젝트 아이디 받아서 dolce api 조회시 사용
const projectId = searchParams.get('projectId')
const sourceSystem = searchParams.get('sourceSystem') || 'DOLCE'
if (!projectId) {
debugError(`필수 파라미터 누락`, { projectId, sourceSystem })
return NextResponse.json(
{ error: 'Project ID is required' },
{ status: 400 }
)
}
debugProcess(`DOLCE 상태 조회 API 호출`, {
projectId,
sourceSystem,
userId: session.user.id
})
const status = await importService.getImportStatus(
Number(projectId),
sourceSystem
)
debugSuccess(`DOLCE 상태 조회 완료`, {
projectId,
availableDocuments: status.availableDocuments,
newDocuments: status.newDocuments,
updatedDocuments: status.updatedDocuments,
availableAttachments: status.availableAttachments,
newAttachments: status.newAttachments,
importEnabled: status.importEnabled
})
return NextResponse.json(status)
} catch (error) {
debugError(`DOLCE 상태 조회 실패`, {
projectId: request.nextUrl.searchParams.get('projectId'),
error
})
return NextResponse.json(
{
error: 'Failed to get import status',
message: error instanceof Error ? error.message : 'Unknown error'
},
{ status: 500 }
)
}
}
|