IO-3330 CARFAX Datapump

Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
Allan Carr
2025-08-14 08:44:10 -07:00
parent e5dd1edf13
commit 7873405a30

View File

@@ -67,15 +67,15 @@ 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") {
res.sendStatus(403);
return;
}
// 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) {
res.sendStatus(401);
return;
}
// Send immediate response and continue processing.
res.status(202).json({
@@ -143,7 +143,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
});
const carfaxObject = {
shopid: bodyshop.imexshopid,
shopid: bodyshop.imexshopid.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
shop_name: bodyshop.shopname,
job: jobs.map((j) =>
CreateRepairOrderTag({ ...j, bodyshop: bodyshops_by_pk }, function ({ job, error }) {
@@ -161,9 +161,9 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
const jsonObj = {
bodyshopid: bodyshop.id,
imexshopid: bodyshop.imexshopid,
imexshopid: bodyshop.imexshopid.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
json: JSON.stringify(carfaxObject, null, 2),
filename: `${bodyshop.imexshopid}_${moment().format("DDMMYYYY_HHMMss")}.json`,
filename: `${bodyshop.imexshopid.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()}_${moment().format("DDMMYYYY_HHMMss")}.json`,
count: carfaxObject.job.length
};
@@ -175,7 +175,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
allXMLResults.push({
bodyshopid: bodyshop.id,
imexshopid: bodyshop.imexshopid,
imexshopid: bodyshop.imexshopid.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
count: jsonObj.count,
filename: jsonObj.filename,
result: jsonObj.result
@@ -190,7 +190,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
allErrors.push({
bodyshopid: bodyshop.id,
imexshopid: bodyshop.imexshopid,
imexshopid: bodyshop.imexshopid.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
CARFAXid: bodyshop.CARFAXid,
fatal: true,
errors: [error.toString()]
@@ -198,7 +198,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
} finally {
allErrors.push({
bodyshopid: bodyshop.id,
imexshopid: bodyshop.imexshopid,
imexshopid: bodyshop.imexshopid.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
CARFAXid: bodyshop.CARFAXid,
errors: erroredJobs.map((ej) => ({
ro_number: ej.job?.ro_number,