diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/soap/mdg/send/vendor-master/action.ts | 123 |
1 files changed, 52 insertions, 71 deletions
diff --git a/lib/soap/mdg/send/vendor-master/action.ts b/lib/soap/mdg/send/vendor-master/action.ts index 46d6e71f..b353eab0 100644 --- a/lib/soap/mdg/send/vendor-master/action.ts +++ b/lib/soap/mdg/send/vendor-master/action.ts @@ -143,6 +143,14 @@ export async function sendVendorMasterToMDG(vendorCodes: string[]): Promise<{ const soapData = buildSoapData(vendorData); console.log(`๐ VENDOR ${vendorCode} SOAP ๋ฐ์ดํฐ ์์ฑ ์๋ฃ`); + // ๋ฐ์ดํฐ ๊ตฌ์กฐ ๊ฒ์ฆ (๋๋ฒ๊น
์ฉ) + const validation = validateSoapDataStructure(soapData); + if (!validation.isValid) { + console.warn(`โ ๏ธ VENDOR ${vendorCode} ๋ฐ์ดํฐ ๊ตฌ์กฐ ๋ฌธ์ :`, validation.issues); + } else { + console.log(`โ
VENDOR ${vendorCode} ๋ฐ์ดํฐ ๊ตฌ์กฐ ๊ฒ์ฆ ํต๊ณผ`); + } + // SOAP ํด๋ผ์ด์ธํธ๋ก ์์ฒญ ์ ์ก await withSoapLogging( 'OUTBOUND', @@ -311,11 +319,10 @@ function buildSoapData(vendorData: NonNullable<Awaited<ReturnType<typeof fetchVe supplierMaster[f.field] = mapping[f.field] ?? ''; }); - // SOAP ์์ฒญ ๊ตฌ์กฐ ์์ฑ + // SOAP ์์ฒญ ๊ตฌ์กฐ ์์ฑ (P2MD3007_S ์ค๋ณต ์ ๊ฑฐ) + // SOAP ํด๋ผ์ด์ธํธ๊ฐ MT_P2MD3007_S๋ก ๋ํํ๋ฏ๋ก, ์ฌ๊ธฐ์๋ SUPPLIER_MASTER๋ง ๋ฐํ return { - P2MD3007_S: { - SUPPLIER_MASTER: supplierMaster - } + SUPPLIER_MASTER: supplierMaster }; } @@ -570,6 +577,34 @@ export async function sendRecentModifiedVendorsToMDG( } } +// SOAP ๋ฐ์ดํฐ ๊ตฌ์กฐ ๊ฒ์ฆ ์ ํธ๋ฆฌํฐ ํจ์ +export function validateSoapDataStructure(soapData: Record<string, unknown>): { + isValid: boolean; + structure: string; + issues: string[]; +} { + const issues: string[] = []; + + // ์ฌ๋ฐ๋ฅธ ๊ตฌ์กฐ์ธ์ง ํ์ธ + if (!soapData.SUPPLIER_MASTER) { + issues.push('SUPPLIER_MASTER ํ๋๊ฐ ์์ต๋๋ค.'); + } + + // P2MD3007_S ์ค๋ณต ํ์ธ (์ด์ ๋ ์์ด์ผ ํจ) + if (soapData.P2MD3007_S) { + issues.push('P2MD3007_S ๋ํ์ด ๋ฐ๊ฒฌ๋์์ต๋๋ค. ์ค๋ณต ๊ตฌ์กฐ๋ก ์ธํด ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค.'); + } + + // ๊ตฌ์กฐ ์ถ๋ ฅ + const structure = JSON.stringify(soapData, null, 2); + + return { + isValid: issues.length === 0, + structure, + issues + }; +} + // ํต๊ณ ์กฐํ ์ ํธ๋ฆฌํฐ ํจ์ export async function getVendorSendStatistics(): Promise<{ total: number; @@ -668,13 +703,23 @@ export async function sendTestVendorDataToMDG(formData: Record<string, string>): // SOAP ์์ฒญ ๊ตฌ์กฐ ์์ฑ const soapData = { - P2MD3007_S: { - SUPPLIER_MASTER: supplierMaster - } + SUPPLIER_MASTER: supplierMaster }; console.log('๐ ํ
์คํธ SOAP ๋ฐ์ดํฐ ์์ฑ ์๋ฃ'); + // ๋ฐ์ดํฐ ๊ตฌ์กฐ ๊ฒ์ฆ (๋๋ฒ๊น
์ฉ) + const validation = validateSoapDataStructure(soapData); + if (!validation.isValid) { + console.warn('โ ๏ธ ํ
์คํธ ๋ฐ์ดํฐ ๊ตฌ์กฐ ๋ฌธ์ :', validation.issues); + return { + success: false, + message: `๋ฐ์ดํฐ ๊ตฌ์กฐ ์ค๋ฅ: ${validation.issues.join(', ')}` + }; + } else { + console.log('โ
ํ
์คํธ ๋ฐ์ดํฐ ๊ตฌ์กฐ ๊ฒ์ฆ ํต๊ณผ'); + } + // SOAP ํด๋ผ์ด์ธํธ๋ก ์์ฒญ ์ ์ก const responseData = await withSoapLogging( 'OUTBOUND', @@ -712,68 +757,4 @@ export async function sendTestVendorDataToMDG(formData: Record<string, string>): } } -// ์ง์ XML ์ ์ก ํจ์ (๊ธฐ์กด ํธํ์ฑ ์ ์ง) -export async function sendVendorEnvelopeToMDG(envelope: string): Promise<{ - success: boolean; - message: string; - responseText?: string; -}> { - try { - const responseText = await withSoapLogging( - 'OUTBOUND', - 'MDG', - 'IF_MDZ_EVCP_VENDOR_MASTER_TEST', // ํ
์คํธ์ฉ ์ธํฐํ์ด์ค๋ช
- envelope, - async () => { - // ์ง์ XML ์ ์ก์ ๊ฒฝ์ฐ ๊ธฐ์กด fetch ๋ฐฉ์ ์ ์ง - const MDG_ENDPOINT_URL = "http://shii8dvddb01.hec.serp.shi.samsung.net:50000/sap/xi/engine?type=entry&version=3.0&Sender.Service=P2038_Q&Interface=http%3A%2F%2Fshi.samsung.co.kr%2FP2_MD%2FMDZ%5EP2MD3007_AO&QualityOfService=ExactlyOnce"; - - // ์ธ์ฆ ํค๋ ์ค๋น - const headers: Record<string, string> = { - 'Content-Type': 'text/xml; charset=utf-8', - 'SOAPAction': 'http://sap.com/xi/WebService/soap1.1', - }; - - // Basic Authentication ํค๋ ์ถ๊ฐ - if (MDG_SOAP_USERNAME && MDG_SOAP_PASSWORD) { - const credentials = Buffer.from(`${MDG_SOAP_USERNAME}:${MDG_SOAP_PASSWORD}`).toString('base64'); - headers['Authorization'] = `Basic ${credentials}`; - console.log('๐ Basic Authentication ํค๋ ์ถ๊ฐ ์๋ฃ'); - } else { - console.warn('โ ๏ธ MDG SOAP ์ธ์ฆ ์ ๋ณด๊ฐ ํ๊ฒฝ๋ณ์์ ์ค์ ๋์ง ์์์ต๋๋ค.'); - } - - const res = await fetch(MDG_ENDPOINT_URL, { - method: 'POST', - headers, - body: envelope, - }); - - const text = await res.text(); - - if (!res.ok) { - throw new Error(`HTTP ${res.status}: ${res.statusText}`); - } - - // SOAP Fault ๊ฒ์ฌ - if (text.includes('soap:Fault') || text.includes('SOAP:Fault')) { - throw new Error(`MDG SOAP Fault: ${text}`); - } - - return text; - } - ); - return { - success: true, - message: '์ ์ก ์ฑ๊ณต', - responseText, - }; - } catch (error) { - console.error('XML ์ ์ก ์คํจ:', error); - return { - success: false, - message: error instanceof Error ? error.message : 'Unknown error', - }; - } -} |
