diff options
| author | joonhoekim <26rote@gmail.com> | 2025-10-29 16:24:28 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-10-29 16:24:28 +0900 |
| commit | bfc26491991997b5b109af6ea6bc75a8be138e9a (patch) | |
| tree | 7d96aa8ae01d43b46f42b3bb57b8b3dedd10c8cb /lib/swp/api-client.ts | |
| parent | 2ecdac866c19abea0b5389708fcdf5b3889c969a (diff) | |
(김준회) fix: SWP 업로드건 벤더 취소 기능 API 응답에 맞춰 수정
Diffstat (limited to 'lib/swp/api-client.ts')
| -rw-r--r-- | lib/swp/api-client.ts | 61 |
1 files changed, 57 insertions, 4 deletions
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; } |
