diff options
Diffstat (limited to 'lib/swp')
| -rw-r--r-- | lib/swp/actions.ts | 12 | ||||
| -rw-r--r-- | lib/swp/api-client.ts | 61 |
2 files changed, 66 insertions, 7 deletions
diff --git a/lib/swp/actions.ts b/lib/swp/actions.ts index eea8c9c2..6962884e 100644 --- a/lib/swp/actions.ts +++ b/lib/swp/actions.ts @@ -518,15 +518,21 @@ export async function cancelVendorUploadedFile(params: CancelUploadedFileParams) debugLog(`[cancelVendorUploadedFile] 취소 시작`, params); const { callSaveInBoxListCancelStatus } = await import("./api-client"); - await callSaveInBoxListCancelStatus({ + const cancelCount = await callSaveInBoxListCancelStatus({ boxSeq: params.boxSeq, actvSeq: params.actvSeq, chgr: `evcp${params.userId}`, }); - debugSuccess(`[cancelVendorUploadedFile] 취소 완료`, params); + debugSuccess(`[cancelVendorUploadedFile] 취소 완료`, { + ...params, + cancelCount + }); - return { success: true }; + return { + success: true, + cancelCount + }; } catch (error) { debugError(`[cancelVendorUploadedFile] 취소 실패`, { error }); throw new Error( diff --git a/lib/swp/api-client.ts b/lib/swp/api-client.ts index 3ac980fb..4943a42a 100644 --- a/lib/swp/api-client.ts +++ b/lib/swp/api-client.ts @@ -157,6 +157,55 @@ async function callSwpApi<T>( } } +/** + * SWP API 호출 (단일 값 반환용) + * 배열이 아닌 단일 값(숫자, 문자열 등)을 반환하는 API용 + */ +async function callSwpApiSingle<T>( + endpoint: string, + body: Record<string, unknown>, + resultKey: string +): Promise<T> { + const url = `${SWP_BASE_URL}/Services/WebService.svc/${endpoint}`; + + console.log(`[SWP API] 호출: ${endpoint}`, body); + + try { + const response = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(body), + signal: AbortSignal.timeout(30000), // 30초 + }); + + if (!response.ok) { + throw new Error( + `SWP API 오류: ${response.status} ${response.statusText}` + ); + } + + const data = await response.json(); + + if (data[resultKey] === undefined) { + throw new Error(`API 응답 형식 오류: ${resultKey} 없음`); + } + + console.log(`[SWP API] 성공: ${endpoint}`, data[resultKey]); + + return data[resultKey] as T; + } catch (error) { + if (error instanceof Error) { + if (error.name === "AbortError") { + throw new Error(`API 타임아웃: 30초 초과`); + } + throw new Error(`${endpoint} 실패: ${error.message}`); + } + throw error; + } +} + // ============================================================================ // 서버 액션: 문서 리스트 조회 // ============================================================================ @@ -346,7 +395,7 @@ export async function analyzeSwpData( // 총 파일 사이즈 (숫자로 변환 가능한 것만) const totalFileSize = files.reduce((sum, f) => { - const size = parseInt(f.FILE_SZ, 10); + const size = f.FILE_SZ ? parseInt(f.FILE_SZ, 10) : 0; return sum + (isNaN(size) ? 0 : size); }, 0); @@ -435,20 +484,24 @@ export interface CancelFileParams { /** * 파일 취소 API (SaveInBoxListCancelStatus) + * @returns 취소된 파일 개수 */ export async function callSaveInBoxListCancelStatus( params: CancelFileParams -): Promise<void> { +): Promise<number> { const body = { boxSeq: params.boxSeq, actvSeq: params.actvSeq, chgr: params.chgr, }; - await callSwpApi( + // 응답 키는 "SaveInBoxCancelStatusResult" (List 없음) + const result = await callSwpApiSingle<number>( "SaveInBoxListCancelStatus", body, - "SaveInBoxListCancelStatusResult" + "SaveInBoxCancelStatusResult" ); + + return result; } |
