IO-3386 CARFAX RPS
Add Brad Rhoades to Report Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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} <noreply@imex.online>`,
|
||||
rome: `Rome Online API - ${process.env.NODE_ENV} <noreply@romeonline.io>`
|
||||
}),
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user