summaryrefslogtreecommitdiff
path: root/app/api/cron/forms/status/route.ts
blob: c0e27b2e077370d20b4f1b4f37b9e7a4b1a8ba94 (plain)
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
// app/api/cron/forms/status/route.ts
import { NextRequest } from 'next/server';
import { getSyncJobStatus } from '../start/route';

export async function GET(request: NextRequest) {
  try {
    // URL에서 작업 ID 가져오기
    const searchParams = request.nextUrl.searchParams;
    const syncId = searchParams.get('id');
    
    if (!syncId) {
      return Response.json({
        success: false,
        error: 'Missing sync ID parameter'
      }, { status: 400 });
    }
    
    // 작업 상태 조회
    const jobStatus = getSyncJobStatus(syncId);
    
    if (!jobStatus) {
      return Response.json({
        success: false,
        error: 'Sync job not found'
      }, { status: 404 });
    }
    
    // 작업 상태 반환
    return Response.json({
      success: true,
      status: jobStatus.status,
      startTime: jobStatus.startTime,
      endTime: jobStatus.endTime,
      progress: jobStatus.progress,
      result: jobStatus.result,
      error: jobStatus.error
    }, { status: 200 });
    
  } catch (error: any) {
    console.error('Error retrieving sync status:', error);
    return Response.json({
      success: false,
      error: error.message || 'Failed to retrieve sync status'
    }, { status: 500 });
  }
}