From 3aff35bb15a80417306c6ae36de5434a44324432 Mon Sep 17 00:00:00 2001 From: joseph le Date: Wed, 11 Oct 2023 15:23:03 +0700 Subject: [PATCH] Create function check status for other system --- app/utils/sendStatusOtherSystem.js | 113 ++++++++++++++++++----------- 1 file changed, 69 insertions(+), 44 deletions(-) diff --git a/app/utils/sendStatusOtherSystem.js b/app/utils/sendStatusOtherSystem.js index 986b3a7..632f718 100644 --- a/app/utils/sendStatusOtherSystem.js +++ b/app/utils/sendStatusOtherSystem.js @@ -69,7 +69,7 @@ const checkMultipleRequest = async () => { // }, // data: {}, // name: "Erp Sync Order Ebay", - // group: "Ebay Systems" + // group: "Ebay Systems", // }, // { // url: "https://disti.danielvu.com/api/sendBuyerOrderToERP", @@ -83,7 +83,7 @@ const checkMultipleRequest = async () => { // }, // data: {}, // name: "Erp Sync PO Ebay", - // group: "Ebay Systems" + // group: "Ebay Systems", // }, // //ERP Systems // { @@ -98,7 +98,7 @@ const checkMultipleRequest = async () => { // filter: {}, // }, // name: "Log SN to ERP", - // group: "ERP Systems" + // group: "ERP Systems", // }, // { // url: "https://int.ipsupply.com.au/api/transferGetData", @@ -459,11 +459,10 @@ const checkMultipleRequest = async () => { // countryCode: "AU", // }, // to: { - // streetLines: ["600 Terminal Dr"], - // city: "Louisville", - // stateOrProvinceCode: "KY", - // postalCode: "40209", - // countryCode: "US", + // streetLines: ["112 Munro St"], + // city: "South Melbourne", + // postalCode: "3205", + // countryCode: "AU", // }, // requestedPackageLineItems: [ // { @@ -524,11 +523,10 @@ const checkMultipleRequest = async () => { // countryCode: "AU", // }, // to: { - // streetLines: ["600 Terminal Dr"], - // city: "Louisville", - // stateOrProvinceCode: "KY", - // postalCode: "40209", - // countryCode: "US", + // streetLines: ["112 Munro St"], + // city: "South Melbourne", + // postalCode: "3205", + // countryCode: "AU", // }, // requestedPackageLineItems: [ // { @@ -764,14 +762,60 @@ const checkMultipleRequest = async () => { lengthOrData: response.data?.data?.length | response.data, }); } else { - if (Array.isArray(response.data.data) === false) { - const data = JSON.stringify( - response.data?.data - )?.toLocaleLowerCase(); + if (response.data?.data !== undefined) { + if (Array.isArray(response.data.data) === false) { + const data = JSON.stringify( + response.data?.data + )?.toLocaleLowerCase(); + if ( + data?.includes("error") || + data?.includes("invalid") || + response.data.data === undefined + ) { + report.push({ + group: req.group, + name: req.name, + status: ":red_circle:", + code: response.status, + lengthOrData: JSON.stringify(response.data?.data), + }); + } else { + report.push({ + group: req.group, + name: req.name, + status: ":check:", + code: response.status, + lengthOrData: response.data?.data?.length, + }); + } + } else { + if ( + response.data?.data !== undefined && + response.data?.data?.length > 0 + ) { + report.push({ + group: req.group, + name: req.name, + status: ":check:", + code: response.status, + lengthOrData: response.data?.data?.length, + }); + } else { + report.push({ + group: req.group, + name: req.name, + status: ":red_circle:", + code: response.status, + lengthOrData: JSON.stringify(response.data?.data), + }); + } + } + } else { + const data = JSON.stringify(response.data)?.toLocaleLowerCase(); if ( data?.includes("error") || data?.includes("invalid") || - response.data.data === undefined + response.data === undefined ) { report.push({ group: req.group, @@ -789,27 +833,6 @@ const checkMultipleRequest = async () => { lengthOrData: response.data?.data?.length, }); } - } else { - if ( - response.data?.data !== undefined && - response.data?.data?.length > 0 - ) { - report.push({ - group: req.group, - name: req.name, - status: ":check:", - code: response.status, - lengthOrData: response.data?.data?.length, - }); - } else { - report.push({ - group: req.group, - name: req.name, - status: ":red_circle:", - code: response.status, - lengthOrData: JSON.stringify(response.data?.data), - }); - } } } } else { @@ -861,7 +884,9 @@ const checkMultipleRequest = async () => { lengthOrData: "Error: " + error, }); }); - } else { + } + + if (req.method === "GET") { await axios .get(req.url, req.data, { headers: req.headers, @@ -885,17 +910,17 @@ const checkMultipleRequest = async () => { }); } - if(req.method === "SSH"){ + if (req.method === "SSH") { exec(req.url, (error, stdout, stderr) => { if (error) { // console.error(`Error executing command: ${error.message}`); return; } - + if (stdout !== "") { - console.log(stdout) + console.log(stdout); } else { - console.log(stderr) + console.log(stderr); } }); }