IO-3330 CARFAX Datapump
Prep for express upgrade with return Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
@@ -68,13 +68,11 @@ const uploadToS3 = (jsonObj) => {
|
||||
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.
|
||||
@@ -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?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
|
||||
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?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
|
||||
imexshopid: shopid,
|
||||
json: JSON.stringify(carfaxObject, null, 2),
|
||||
filename: `${bodyshop.imexshopid?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()}_${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?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
|
||||
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?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
|
||||
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?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
|
||||
imexshopid: shopid,
|
||||
CARFAXid: bodyshop.CARFAXid,
|
||||
errors: erroredJobs.map((ej) => ({
|
||||
ro_number: ej.job?.ro_number,
|
||||
|
||||
Reference in New Issue
Block a user