diff --git a/server/data/autohouse.js b/server/data/autohouse.js index 81679522b..586d9789b 100644 --- a/server/data/autohouse.js +++ b/server/data/autohouse.js @@ -3,7 +3,6 @@ const queries = require("../graphql-client/queries"); const Dinero = require("dinero.js"); const moment = require("moment-timezone"); var builder = require("xmlbuilder2"); -const _ = require("lodash"); const logger = require("../utils/logger"); const fs = require("fs"); require("dotenv").config({ @@ -16,6 +15,7 @@ const { sendServerEmail } = require("../email/sendemail"); const AHDineroFormat = "0.00"; const AhDateFormat = "MMDDYYYY"; +const NON_ASCII_REGEX = /[^\x20-\x7E]/g; const repairOpCodes = ["OP4", "OP9", "OP10"]; const replaceOpCodes = ["OP2", "OP5", "OP11", "OP12"]; @@ -37,13 +37,11 @@ const ftpSetup = { exports.default = async (req, res) => { // Only process if in production environment. if (process.env.NODE_ENV !== "production") { - res.sendStatus(403); - return; + return res.sendStatus(403); } // Only process if the appropriate token is provided. if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) { - res.sendStatus(401); - return; + return res.sendStatus(401); } // Send immediate response and continue processing. @@ -822,7 +820,7 @@ const GenerateDetailLines = (job, line, statuses) => { BackOrdered: line.status === statuses.default_bo ? "1" : "0", Cost: (line.billlines[0] && (line.billlines[0].actual_cost * line.billlines[0].quantity).toFixed(2)) || 0, //Critical: null, - Description: line.line_desc ? line.line_desc.replace(/[^\x00-\x7F]/g, "") : "", + Description: line.line_desc ? line.line_desc.replace(NON_ASCII_REGEX, "") : "", DiscountMarkup: line.prt_dsmk_m || 0, InvoiceNumber: line.billlines[0] && line.billlines[0].bill.invoice_number, IOUPart: 0, @@ -834,7 +832,7 @@ const GenerateDetailLines = (job, line, statuses) => { OriginalCost: null, OriginalInvoiceNumber: null, PriceEach: line.act_price || 0, - PartNumber: line.oem_partno ? line.oem_partno.replace(/[^\x00-\x7F]/g, "") : "", + PartNumber: line.oem_partno ? line.oem_partno.replace(NON_ASCII_REGEX, "") : "", ProfitPercent: null, PurchaseOrderNumber: null, Qty: line.part_qty || 0, diff --git a/server/data/carfax.js b/server/data/carfax.js index 855755f37..e1583a365 100644 --- a/server/data/carfax.js +++ b/server/data/carfax.js @@ -67,15 +67,13 @@ const uploadToS3 = (jsonObj) => { exports.default = async (req, res) => { // Only process if in production environment. - // if (process.env.NODE_ENV !== "production") { - // res.sendStatus(403); - // return; - // } + if (process.env.NODE_ENV !== "production") { + return res.sendStatus(403); + } // Only process if the appropriate token is provided. - // if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) { - // res.sendStatus(401); - // return; - // } + if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) { + return res.sendStatus(401); + } // Send immediate response and continue processing. res.status(202).json({ @@ -126,6 +124,7 @@ exports.default = async (req, res) => { async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allXMLResults, allErrors) { for (const bodyshop of shopsToProcess) { + const shopid = bodyshop.imexshopid?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase() const erroredJobs = []; try { logger.log("CARFAX-start-shop-extract", "DEBUG", "api", bodyshop.id, { @@ -143,7 +142,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat }); const carfaxObject = { - shopid: bodyshop.imexshopid, + shopid: shopid, shop_name: bodyshop.shopname, job: jobs.map((j) => CreateRepairOrderTag({ ...j, bodyshop: bodyshops_by_pk }, function ({ job, error }) { @@ -161,9 +160,9 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat const jsonObj = { bodyshopid: bodyshop.id, - imexshopid: bodyshop.imexshopid, + imexshopid: shopid, json: JSON.stringify(carfaxObject, null, 2), - filename: `${bodyshop.imexshopid}_${moment().format("DDMMYYYY_HHMMss")}.json`, + filename: `${shopid}_${moment().format("DDMMYYYY_HHMMss")}.json`, count: carfaxObject.job.length }; @@ -175,7 +174,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat allXMLResults.push({ bodyshopid: bodyshop.id, - imexshopid: bodyshop.imexshopid, + imexshopid: shopid, count: jsonObj.count, filename: jsonObj.filename, result: jsonObj.result @@ -190,7 +189,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat allErrors.push({ bodyshopid: bodyshop.id, - imexshopid: bodyshop.imexshopid, + imexshopid: shopid, CARFAXid: bodyshop.CARFAXid, fatal: true, errors: [error.toString()] @@ -198,7 +197,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat } finally { allErrors.push({ bodyshopid: bodyshop.id, - imexshopid: bodyshop.imexshopid, + imexshopid: shopid, CARFAXid: bodyshop.CARFAXid, errors: erroredJobs.map((ej) => ({ ro_number: ej.job?.ro_number, diff --git a/server/data/chatter.js b/server/data/chatter.js index 3f84988ca..c54a58c2c 100644 --- a/server/data/chatter.js +++ b/server/data/chatter.js @@ -28,13 +28,11 @@ const ftpSetup = { exports.default = async (req, res) => { // Only process if in production environment. if (process.env.NODE_ENV !== "production") { - res.sendStatus(403); - return; + return res.sendStatus(403); } // Only process if the appropriate token is provided. if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) { - res.sendStatus(401); - return; + return res.sendStatus(401); } // Send immediate response and continue processing. diff --git a/server/data/claimscorp.js b/server/data/claimscorp.js index 70737bd03..cadeef606 100644 --- a/server/data/claimscorp.js +++ b/server/data/claimscorp.js @@ -3,7 +3,6 @@ const queries = require("../graphql-client/queries"); const Dinero = require("dinero.js"); const moment = require("moment-timezone"); var builder = require("xmlbuilder2"); -const _ = require("lodash"); const logger = require("../utils/logger"); const fs = require("fs"); require("dotenv").config({ @@ -36,13 +35,11 @@ const ftpSetup = { exports.default = async (req, res) => { // Only process if in production environment. if (process.env.NODE_ENV !== "production") { - res.sendStatus(403); - return; + return res.sendStatus(403); } // Only process if the appropriate token is provided. if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) { - res.sendStatus(401); - return; + return res.sendStatus(401); } // Send immediate response and continue processing. diff --git a/server/data/kaizen.js b/server/data/kaizen.js index 897a57770..d8d3a9dc5 100644 --- a/server/data/kaizen.js +++ b/server/data/kaizen.js @@ -3,7 +3,6 @@ const queries = require("../graphql-client/queries"); const Dinero = require("dinero.js"); const moment = require("moment-timezone"); var builder = require("xmlbuilder2"); -const _ = require("lodash"); const logger = require("../utils/logger"); const fs = require("fs"); require("dotenv").config({ @@ -35,13 +34,11 @@ const ftpSetup = { exports.default = async (req, res) => { // Only process if in production environment. if (process.env.NODE_ENV !== "production") { - res.sendStatus(403); - return; + return res.sendStatus(403); } // Only process if the appropriate token is provided. if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) { - res.sendStatus(401); - return; + return res.sendStatus(401); } // Send immediate response and continue processing. diff --git a/server/data/podium.js b/server/data/podium.js index 9f6327ef4..5490b00db 100644 --- a/server/data/podium.js +++ b/server/data/podium.js @@ -29,13 +29,11 @@ const ftpSetup = { exports.default = async (req, res) => { // Only process if in production environment. if (process.env.NODE_ENV !== "production") { - res.sendStatus(403); - return; + return res.sendStatus(403); } // Only process if the appropriate token is provided. if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) { - res.sendStatus(401); - return; + return res.sendStatus(401); } // Send immediate response and continue processing.