diff --git a/server/data/carfax-rps.js b/server/data/carfax-rps.js index 9455ee7fe..d6065df57 100644 --- a/server/data/carfax-rps.js +++ b/server/data/carfax-rps.js @@ -33,7 +33,7 @@ const carfaxExportRps = async (req, res) => { try { logger.log("CARFAX-RPS-start", "DEBUG", "api", null, null); - const allXMLResults = []; + const allJSONResults = []; const allErrors = []; const { bodyshops } = await client.request(queries.GET_CARFAX_RPS_SHOPS); //Query for the List of Bodyshop Clients. @@ -49,12 +49,12 @@ const carfaxExportRps = async (req, res) => { return; } - await processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allXMLResults, allErrors); + await processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allJSONResults, allErrors); await sendServerEmail({ subject: `Project Mexico RPS Report ${moment().format("MM-DD-YY")}`, - text: `Errors:\n${JSON.stringify(allErrors, null, 2)}\n\nUploaded:\n${JSON.stringify( - allXMLResults.map((x) => ({ + text: `Total Count: ${allJSONResults.reduce((a, v) => a + v.count, 0)}\nErrors:\n${JSON.stringify(allErrors, null, 2)}\n\nUploaded:\n${JSON.stringify( + allJSONResults.map((x) => ({ imexshopid: x.imexshopid, filename: x.filename, count: x.count, @@ -62,7 +62,8 @@ const carfaxExportRps = async (req, res) => { })), null, 2 - )}` + )}`, + to: ["bradley.rhoades@convenient-brands.com"] }); logger.log("CARFAX-RPS-end", "DEBUG", "api", null, null); @@ -71,7 +72,7 @@ const carfaxExportRps = async (req, res) => { } }; -async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allXMLResults, allErrors) { +async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allJSONResults, allErrors) { for (const bodyshop of shopsToProcess) { const shopid = bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(); const erroredJobs = []; @@ -148,7 +149,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat }); } - allXMLResults.push({ + allJSONResults.push({ bodyshopid: bodyshop.id, imexshopid: shopid, count: jsonObj.count, diff --git a/server/data/carfax.js b/server/data/carfax.js index dbbcf3464..f2ff0bac2 100644 --- a/server/data/carfax.js +++ b/server/data/carfax.js @@ -80,7 +80,7 @@ const carfaxExport = async (req, res) => { try { logger.log("CARFAX-start", "DEBUG", "api", null, null); - const allXMLResults = []; + const allJSONResults = []; const allErrors = []; const { bodyshops } = await client.request(queries.GET_CARFAX_SHOPS); //Query for the List of Bodyshop Clients. @@ -96,12 +96,12 @@ const carfaxExport = async (req, res) => { return; } - await processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allXMLResults, allErrors); + await processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allJSONResults, allErrors); await sendServerEmail({ subject: `Project Mexico Report ${moment().format("MM-DD-YY")}`, - text: `Errors:\n${JSON.stringify(allErrors, null, 2)}\n\nUploaded:\n${JSON.stringify( - allXMLResults.map((x) => ({ + text: `Total Count: ${allJSONResults.reduce((a, v) => a + v.count, 0)}\nErrors:\n${JSON.stringify(allErrors, null, 2)}\n\nUploaded:\n${JSON.stringify( + allJSONResults.map((x) => ({ imexshopid: x.imexshopid, filename: x.filename, count: x.count, @@ -109,7 +109,8 @@ const carfaxExport = async (req, res) => { })), null, 2 - )}` + )}`, + to: ["bradley.rhoades@convenient-brands.com"] }); logger.log("CARFAX-end", "DEBUG", "api", null, null); @@ -118,7 +119,7 @@ const carfaxExport = async (req, res) => { } }; -async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allXMLResults, allErrors) { +async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allJSONResults, allErrors) { for (const bodyshop of shopsToProcess) { const shopid = bodyshop.imexshopid?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(); const erroredJobs = []; @@ -195,7 +196,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat }); } - allXMLResults.push({ + allJSONResults.push({ bodyshopid: bodyshop.id, imexshopid: shopid, count: jsonObj.count, diff --git a/server/email/sendemail.js b/server/email/sendemail.js index f953f1bf0..864031462 100644 --- a/server/email/sendemail.js +++ b/server/email/sendemail.js @@ -44,8 +44,14 @@ const logEmail = async (req, email) => { } }; -const sendServerEmail = async ({ subject, text }) => { +const sendServerEmail = async ({ subject, text, to = [] }) => { if (process.env.NODE_ENV === undefined) return; + + let sentTo = ["support@imexsystems.ca"]; + if (to?.length) { + sentTo = [...sentTo, ...to]; + } + try { mailer.sendMail( { @@ -53,7 +59,7 @@ const sendServerEmail = async ({ subject, text }) => { imex: `ImEX Online API - ${process.env.NODE_ENV} `, rome: `Rome Online API - ${process.env.NODE_ENV} ` }), - to: ["support@thinkimex.com"], + to: sentTo, subject: subject, text: text, ses: { @@ -258,7 +264,10 @@ const sendTaskEmail = async ({ to, subject, type = "text", html, text, attachmen // eslint-disable-next-line no-unused-vars (err, info) => { // (message, type, user, record, meta - logger.log("server-email-send", err ? "error" : "debug", null, null, { message: err?.message, stack: err?.stack }); + logger.log("server-email-send", err ? "error" : "debug", null, null, { + message: err?.message, + stack: err?.stack + }); } ); } catch (error) {