From 4582c493ee91edfb5626ed36c5b3f6f4d3a92456 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Tue, 28 Jun 2022 08:31:24 -0700 Subject: [PATCH 1/2] Autohouse replace fix. --- server/data/autohouse.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/data/autohouse.js b/server/data/autohouse.js index f92863395..47864271b 100644 --- a/server/data/autohouse.js +++ b/server/data/autohouse.js @@ -107,7 +107,7 @@ exports.default = async (req, res) => { } catch (error) { //Error at the shop level. logger.log("autohouse-error-shop", "ERROR", "api", bodyshop.id, { - error, + ...error, }); allErrors.push({ @@ -135,7 +135,7 @@ exports.default = async (req, res) => { let sftp = new Client(); sftp.on("error", (errors) => logger.log("autohouse-sftp-error", "ERROR", "api", null, { - errors, + ...errors, }) ); try { @@ -160,7 +160,7 @@ exports.default = async (req, res) => { //***TODO Change filing naming when creating the cron job. IM_ShopInternalName_DDMMYYYY_HHMMSS.xml } catch (error) { logger.log("autohouse-sftp-error", "ERROR", "api", null, { - error, + ...error, }); } finally { sftp.end(); @@ -185,7 +185,11 @@ const CreateRepairOrderTag = (job, errorCallback) => { //Level 2 if (!job.job_totals) { - errorCallback({ job, error: { toString: () => "No job totals for RO." } }); + errorCallback({ + jobid: jobid, + ro_number: job.ro_number, + error: { toString: () => "No job totals for RO." }, + }); return {}; } @@ -658,7 +662,7 @@ const CreateRepairOrderTag = (job, errorCallback) => { error, }); - errorCallback({ job, error }); + errorCallback({ jobid: jobid, ro_number: job.ro_number, error }); } }; @@ -889,7 +893,9 @@ const GenerateDetailLines = (job, line, statuses) => { OriginalCost: null, OriginalInvoiceNumber: null, PriceEach: line.act_price || 0, - PartNumber: _.escape(line.oem_partno.replace(/[^\x00-\x7F]/g, "")), + PartNumber: line.oem_partno + ? line.oem_partno.replace(/[^\x00-\x7F]/g, "") + : "", ProfitPercent: null, PurchaseOrderNumber: null, Qty: line.part_qty || 0, From fbcf2b559ef48c33f0879e83948b11a3000148f2 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Tue, 28 Jun 2022 08:34:34 -0700 Subject: [PATCH 2/2] Update error handling for autohouse. --- server/data/autohouse.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/server/data/autohouse.js b/server/data/autohouse.js index 47864271b..92851602c 100644 --- a/server/data/autohouse.js +++ b/server/data/autohouse.js @@ -39,7 +39,7 @@ exports.default = async (req, res) => { const { bodyshops } = await client.request(queries.GET_AUTOHOUSE_SHOPS); const specificShopIds = req.body.bodyshopIds; // ['uuid] - const { start, end } = req.body; //YYYY-MM-DD + const { start, end, skipUpload } = req.body; //YYYY-MM-DD const allxmlsToUpload = []; const allErrors = []; try { @@ -125,12 +125,24 @@ exports.default = async (req, res) => { } } - // for (const xmlObj of allxmlsToUpload) { - // fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml); - // } + if (skipUpload) { + for (const xmlObj of allxmlsToUpload) { + fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml); + } - // res.json(allxmlsToUpload); - // return; + res.json(allxmlsToUpload); + sendServerEmail({ + subject: `Autohouse Report ${moment().format("MM-DD-YY")}`, + text: `Errors: ${allErrors.map((e) => JSON.stringify(e, null, 2))} + Uploaded: ${JSON.stringify( + allxmlsToUpload.map((x) => ({ filename: x.filename, count: x.count })), + null, + 2 + )} + `, + }); + return; + } let sftp = new Client(); sftp.on("error", (errors) => @@ -169,7 +181,7 @@ exports.default = async (req, res) => { subject: `Autohouse Report ${moment().format("MM-DD-YY")}`, text: `Errors: ${allErrors.map((e) => JSON.stringify(e, null, 2))} Uploaded: ${JSON.stringify( - allxmlsToUpload.map((x) => x.filename), + allxmlsToUpload.map((x) => ({ filename: x.filename, count: x.count })), null, 2 )}