diff options
| author | joonhoekim <26rote@gmail.com> | 2025-10-10 16:09:06 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-10-10 16:09:06 +0900 |
| commit | f14b7c3e28a6d08537e07f182f5d080d82adf60e (patch) | |
| tree | b7e0947a765043d48cf1e255f9096fd0c0489b6f /lib | |
| parent | 4bac8ab190787d09371691f541627a3eb5866fa6 (diff) | |
(김준회) oracle db knex 응답 구조가 기대와 다른 문제 수정
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pos/get-dcmtm-id.ts | 64 |
1 files changed, 48 insertions, 16 deletions
diff --git a/lib/pos/get-dcmtm-id.ts b/lib/pos/get-dcmtm-id.ts index ae807a84..78c7793b 100644 --- a/lib/pos/get-dcmtm-id.ts +++ b/lib/pos/get-dcmtm-id.ts @@ -47,34 +47,66 @@ export async function getDcmtmIdByMaterialCode( debugProcess(`🗄️ Oracle 쿼리 실행`, { materialCode, query: query.trim() }); const results = await oracleKnex.raw(query, [materialCode]); - debugLog(`🗄️ Oracle 쿼리 결과`, { materialCode, resultType: typeof results, hasRows: results && results[0] ? results[0].length : 0 }); - + debugLog(`🗄️ Oracle 쿼리 결과`, { + materialCode, + resultType: typeof results, + isArray: Array.isArray(results), + resultKeys: results && typeof results === 'object' ? Object.keys(results) : null, + resultLength: Array.isArray(results) ? results.length : null, + resultValue: results + }); + // Oracle 결과 처리 (oracledb 드라이버의 결과 구조에 따라) - // Knex.js oracledb 클라이언트의 결과 구조: - // - 배열 형태: [rows, metaData] - // - 객체 형태: { rows: [...], metaData: [...] } + // Knex.js oracledb 클라이언트의 실제 결과 구조: + // - 데이터 행들의 배열: [{PROJ_NO: '...', ...}, {PROJ_NO: '...', ...}] + // - 또는 [rows, metaData] 형태 + // - 또는 { rows: [...], metaData: [...] } 형태 let rows; if (Array.isArray(results)) { - // [rows, metaData] 형태 - 첫 번째 요소가 실제 데이터 - rows = results[0] || []; - } else if (results.rows) { + debugLog(`🔍 배열 형태 결과 처리`, { + materialCode, + arrayLength: results.length, + firstElementType: typeof results[0], + firstElementIsArray: Array.isArray(results[0]), + firstElementKeys: results[0] && typeof results[0] === 'object' ? Object.keys(results[0]) : null + }); + + // results가 데이터 행들의 배열인지 확인 + if (results.length > 0 && typeof results[0] === 'object' && !Array.isArray(results[0]) && results[0].PROJ_NO) { + // results = [{PROJ_NO: '...', POS_NO: '...', ...}, ...] - 바로 데이터 행들 + rows = results; + } else { + // [rows, metaData] 형태 - 첫 번째 요소가 실제 데이터 + rows = results[0] || []; + } + } else if (results && typeof results === 'object' && results.rows) { + debugLog(`🔍 객체 형태 결과 처리`, { + materialCode, + hasRows: !!results.rows, + rowsType: typeof results.rows, + rowsIsArray: Array.isArray(results.rows), + rowsLength: Array.isArray(results.rows) ? results.rows.length : null + }); + // { rows: [...], metaData: [...] } 형태 rows = results.rows || []; } else { + debugLog(`🔍 기타 형태 결과 처리`, { + materialCode, + resultValue: results + }); + // 직접 배열인 경우 rows = results || []; } - debugLog(`📊 Oracle 결과 구조 분석`, { + debugLog(`📊 최종 rows 추출 결과`, { materialCode, - rawResultType: typeof results, - isRawResultArray: Array.isArray(results), - rawResultKeys: results && typeof results === 'object' ? Object.keys(results) : [], - rawResultLength: Array.isArray(results) ? results.length : (results && typeof results === 'object' ? Object.keys(results).length : 0), - extractedRowsType: typeof rows, - isExtractedRowsArray: Array.isArray(rows), + rowsType: typeof rows, + isRowsArray: Array.isArray(rows), rowCount: Array.isArray(rows) ? rows.length : 0, - firstRow: Array.isArray(rows) && rows.length > 0 ? rows[0] : null + firstRow: Array.isArray(rows) && rows.length > 0 ? rows[0] : null, + firstRowType: Array.isArray(rows) && rows.length > 0 ? typeof rows[0] : null }); if (!Array.isArray(rows) || rows.length === 0) { |
