IO-3386 CARFAX RPS

Add Brad Rhoades to Report

Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
Allan Carr
2025-10-03 11:24:10 -07:00
parent 678a87f55d
commit 4899297539
3 changed files with 28 additions and 17 deletions

View File

@@ -33,7 +33,7 @@ const carfaxExportRps = async (req, res) => {
try { try {
logger.log("CARFAX-RPS-start", "DEBUG", "api", null, null); logger.log("CARFAX-RPS-start", "DEBUG", "api", null, null);
const allXMLResults = []; const allJSONResults = [];
const allErrors = []; const allErrors = [];
const { bodyshops } = await client.request(queries.GET_CARFAX_RPS_SHOPS); //Query for the List of Bodyshop Clients. 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; return;
} }
await processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allXMLResults, allErrors); await processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allJSONResults, allErrors);
await sendServerEmail({ await sendServerEmail({
subject: `Project Mexico RPS Report ${moment().format("MM-DD-YY")}`, subject: `Project Mexico RPS Report ${moment().format("MM-DD-YY")}`,
text: `Errors:\n${JSON.stringify(allErrors, null, 2)}\n\nUploaded:\n${JSON.stringify( text: `Total Count: ${allJSONResults.reduce((a, v) => a + v.count, 0)}\nErrors:\n${JSON.stringify(allErrors, null, 2)}\n\nUploaded:\n${JSON.stringify(
allXMLResults.map((x) => ({ allJSONResults.map((x) => ({
imexshopid: x.imexshopid, imexshopid: x.imexshopid,
filename: x.filename, filename: x.filename,
count: x.count, count: x.count,
@@ -62,7 +62,8 @@ const carfaxExportRps = async (req, res) => {
})), })),
null, null,
2 2
)}` )}`,
to: ["bradley.rhoades@convenient-brands.com"]
}); });
logger.log("CARFAX-RPS-end", "DEBUG", "api", null, null); 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) { for (const bodyshop of shopsToProcess) {
const shopid = bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(); const shopid = bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
const erroredJobs = []; const erroredJobs = [];
@@ -148,7 +149,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
}); });
} }
allXMLResults.push({ allJSONResults.push({
bodyshopid: bodyshop.id, bodyshopid: bodyshop.id,
imexshopid: shopid, imexshopid: shopid,
count: jsonObj.count, count: jsonObj.count,

View File

@@ -80,7 +80,7 @@ const carfaxExport = async (req, res) => {
try { try {
logger.log("CARFAX-start", "DEBUG", "api", null, null); logger.log("CARFAX-start", "DEBUG", "api", null, null);
const allXMLResults = []; const allJSONResults = [];
const allErrors = []; const allErrors = [];
const { bodyshops } = await client.request(queries.GET_CARFAX_SHOPS); //Query for the List of Bodyshop Clients. 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; return;
} }
await processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allXMLResults, allErrors); await processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allJSONResults, allErrors);
await sendServerEmail({ await sendServerEmail({
subject: `Project Mexico Report ${moment().format("MM-DD-YY")}`, subject: `Project Mexico Report ${moment().format("MM-DD-YY")}`,
text: `Errors:\n${JSON.stringify(allErrors, null, 2)}\n\nUploaded:\n${JSON.stringify( text: `Total Count: ${allJSONResults.reduce((a, v) => a + v.count, 0)}\nErrors:\n${JSON.stringify(allErrors, null, 2)}\n\nUploaded:\n${JSON.stringify(
allXMLResults.map((x) => ({ allJSONResults.map((x) => ({
imexshopid: x.imexshopid, imexshopid: x.imexshopid,
filename: x.filename, filename: x.filename,
count: x.count, count: x.count,
@@ -109,7 +109,8 @@ const carfaxExport = async (req, res) => {
})), })),
null, null,
2 2
)}` )}`,
to: ["bradley.rhoades@convenient-brands.com"]
}); });
logger.log("CARFAX-end", "DEBUG", "api", null, null); 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) { for (const bodyshop of shopsToProcess) {
const shopid = bodyshop.imexshopid?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(); const shopid = bodyshop.imexshopid?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
const erroredJobs = []; const erroredJobs = [];
@@ -195,7 +196,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
}); });
} }
allXMLResults.push({ allJSONResults.push({
bodyshopid: bodyshop.id, bodyshopid: bodyshop.id,
imexshopid: shopid, imexshopid: shopid,
count: jsonObj.count, count: jsonObj.count,

View File

@@ -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; if (process.env.NODE_ENV === undefined) return;
let sentTo = ["support@imexsystems.ca"];
if (to?.length) {
sentTo = [...sentTo, ...to];
}
try { try {
mailer.sendMail( mailer.sendMail(
{ {
@@ -53,7 +59,7 @@ const sendServerEmail = async ({ subject, text }) => {
imex: `ImEX Online API - ${process.env.NODE_ENV} <noreply@imex.online>`, imex: `ImEX Online API - ${process.env.NODE_ENV} <noreply@imex.online>`,
rome: `Rome Online API - ${process.env.NODE_ENV} <noreply@romeonline.io>` rome: `Rome Online API - ${process.env.NODE_ENV} <noreply@romeonline.io>`
}), }),
to: ["support@thinkimex.com"], to: sentTo,
subject: subject, subject: subject,
text: text, text: text,
ses: { ses: {
@@ -258,7 +264,10 @@ const sendTaskEmail = async ({ to, subject, type = "text", html, text, attachmen
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
(err, info) => { (err, info) => {
// (message, type, user, record, meta // (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) { } catch (error) {