IO-3330 CARFAX Datapump
Prep for express upgrade with return Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
@@ -3,7 +3,6 @@ const queries = require("../graphql-client/queries");
|
|||||||
const Dinero = require("dinero.js");
|
const Dinero = require("dinero.js");
|
||||||
const moment = require("moment-timezone");
|
const moment = require("moment-timezone");
|
||||||
var builder = require("xmlbuilder2");
|
var builder = require("xmlbuilder2");
|
||||||
const _ = require("lodash");
|
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
require("dotenv").config({
|
require("dotenv").config({
|
||||||
@@ -16,6 +15,7 @@ const { sendServerEmail } = require("../email/sendemail");
|
|||||||
|
|
||||||
const AHDineroFormat = "0.00";
|
const AHDineroFormat = "0.00";
|
||||||
const AhDateFormat = "MMDDYYYY";
|
const AhDateFormat = "MMDDYYYY";
|
||||||
|
const NON_ASCII_REGEX = /[^\x20-\x7E]/g;
|
||||||
|
|
||||||
const repairOpCodes = ["OP4", "OP9", "OP10"];
|
const repairOpCodes = ["OP4", "OP9", "OP10"];
|
||||||
const replaceOpCodes = ["OP2", "OP5", "OP11", "OP12"];
|
const replaceOpCodes = ["OP2", "OP5", "OP11", "OP12"];
|
||||||
@@ -37,13 +37,11 @@ const ftpSetup = {
|
|||||||
exports.default = async (req, res) => {
|
exports.default = async (req, res) => {
|
||||||
// Only process if in production environment.
|
// Only process if in production environment.
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
res.sendStatus(403);
|
return res.sendStatus(403);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Only process if the appropriate token is provided.
|
// Only process if the appropriate token is provided.
|
||||||
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
||||||
res.sendStatus(401);
|
return res.sendStatus(401);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send immediate response and continue processing.
|
// Send immediate response and continue processing.
|
||||||
@@ -822,7 +820,7 @@ const GenerateDetailLines = (job, line, statuses) => {
|
|||||||
BackOrdered: line.status === statuses.default_bo ? "1" : "0",
|
BackOrdered: line.status === statuses.default_bo ? "1" : "0",
|
||||||
Cost: (line.billlines[0] && (line.billlines[0].actual_cost * line.billlines[0].quantity).toFixed(2)) || 0,
|
Cost: (line.billlines[0] && (line.billlines[0].actual_cost * line.billlines[0].quantity).toFixed(2)) || 0,
|
||||||
//Critical: null,
|
//Critical: null,
|
||||||
Description: line.line_desc ? line.line_desc.replace(/[^\x00-\x7F]/g, "") : "",
|
Description: line.line_desc ? line.line_desc.replace(NON_ASCII_REGEX, "") : "",
|
||||||
DiscountMarkup: line.prt_dsmk_m || 0,
|
DiscountMarkup: line.prt_dsmk_m || 0,
|
||||||
InvoiceNumber: line.billlines[0] && line.billlines[0].bill.invoice_number,
|
InvoiceNumber: line.billlines[0] && line.billlines[0].bill.invoice_number,
|
||||||
IOUPart: 0,
|
IOUPart: 0,
|
||||||
@@ -834,7 +832,7 @@ const GenerateDetailLines = (job, line, statuses) => {
|
|||||||
OriginalCost: null,
|
OriginalCost: null,
|
||||||
OriginalInvoiceNumber: null,
|
OriginalInvoiceNumber: null,
|
||||||
PriceEach: line.act_price || 0,
|
PriceEach: line.act_price || 0,
|
||||||
PartNumber: line.oem_partno ? line.oem_partno.replace(/[^\x00-\x7F]/g, "") : "",
|
PartNumber: line.oem_partno ? line.oem_partno.replace(NON_ASCII_REGEX, "") : "",
|
||||||
ProfitPercent: null,
|
ProfitPercent: null,
|
||||||
PurchaseOrderNumber: null,
|
PurchaseOrderNumber: null,
|
||||||
Qty: line.part_qty || 0,
|
Qty: line.part_qty || 0,
|
||||||
|
|||||||
@@ -68,13 +68,11 @@ const uploadToS3 = (jsonObj) => {
|
|||||||
exports.default = async (req, res) => {
|
exports.default = async (req, res) => {
|
||||||
// Only process if in production environment.
|
// Only process if in production environment.
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
res.sendStatus(403);
|
return res.sendStatus(403);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Only process if the appropriate token is provided.
|
// Only process if the appropriate token is provided.
|
||||||
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
||||||
res.sendStatus(401);
|
return res.sendStatus(401);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send immediate response and continue processing.
|
// 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) {
|
async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDateFilter, allXMLResults, 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 erroredJobs = [];
|
const erroredJobs = [];
|
||||||
try {
|
try {
|
||||||
logger.log("CARFAX-start-shop-extract", "DEBUG", "api", bodyshop.id, {
|
logger.log("CARFAX-start-shop-extract", "DEBUG", "api", bodyshop.id, {
|
||||||
@@ -143,7 +142,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
|
|||||||
});
|
});
|
||||||
|
|
||||||
const carfaxObject = {
|
const carfaxObject = {
|
||||||
shopid: bodyshop.imexshopid?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
|
shopid: shopid,
|
||||||
shop_name: bodyshop.shopname,
|
shop_name: bodyshop.shopname,
|
||||||
job: jobs.map((j) =>
|
job: jobs.map((j) =>
|
||||||
CreateRepairOrderTag({ ...j, bodyshop: bodyshops_by_pk }, function ({ job, error }) {
|
CreateRepairOrderTag({ ...j, bodyshop: bodyshops_by_pk }, function ({ job, error }) {
|
||||||
@@ -161,9 +160,9 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
|
|||||||
|
|
||||||
const jsonObj = {
|
const jsonObj = {
|
||||||
bodyshopid: bodyshop.id,
|
bodyshopid: bodyshop.id,
|
||||||
imexshopid: bodyshop.imexshopid?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
|
imexshopid: shopid,
|
||||||
json: JSON.stringify(carfaxObject, null, 2),
|
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
|
count: carfaxObject.job.length
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -175,7 +174,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
|
|||||||
|
|
||||||
allXMLResults.push({
|
allXMLResults.push({
|
||||||
bodyshopid: bodyshop.id,
|
bodyshopid: bodyshop.id,
|
||||||
imexshopid: bodyshop.imexshopid?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
|
imexshopid: shopid,
|
||||||
count: jsonObj.count,
|
count: jsonObj.count,
|
||||||
filename: jsonObj.filename,
|
filename: jsonObj.filename,
|
||||||
result: jsonObj.result
|
result: jsonObj.result
|
||||||
@@ -190,7 +189,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
|
|||||||
|
|
||||||
allErrors.push({
|
allErrors.push({
|
||||||
bodyshopid: bodyshop.id,
|
bodyshopid: bodyshop.id,
|
||||||
imexshopid: bodyshop.imexshopid?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
|
imexshopid: shopid,
|
||||||
CARFAXid: bodyshop.CARFAXid,
|
CARFAXid: bodyshop.CARFAXid,
|
||||||
fatal: true,
|
fatal: true,
|
||||||
errors: [error.toString()]
|
errors: [error.toString()]
|
||||||
@@ -198,7 +197,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
|
|||||||
} finally {
|
} finally {
|
||||||
allErrors.push({
|
allErrors.push({
|
||||||
bodyshopid: bodyshop.id,
|
bodyshopid: bodyshop.id,
|
||||||
imexshopid: bodyshop.imexshopid?.toLowerCase() || bodyshop.shopname.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(),
|
imexshopid: shopid,
|
||||||
CARFAXid: bodyshop.CARFAXid,
|
CARFAXid: bodyshop.CARFAXid,
|
||||||
errors: erroredJobs.map((ej) => ({
|
errors: erroredJobs.map((ej) => ({
|
||||||
ro_number: ej.job?.ro_number,
|
ro_number: ej.job?.ro_number,
|
||||||
|
|||||||
@@ -28,13 +28,11 @@ const ftpSetup = {
|
|||||||
exports.default = async (req, res) => {
|
exports.default = async (req, res) => {
|
||||||
// Only process if in production environment.
|
// Only process if in production environment.
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
res.sendStatus(403);
|
return res.sendStatus(403);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Only process if the appropriate token is provided.
|
// Only process if the appropriate token is provided.
|
||||||
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
||||||
res.sendStatus(401);
|
return res.sendStatus(401);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send immediate response and continue processing.
|
// Send immediate response and continue processing.
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const queries = require("../graphql-client/queries");
|
|||||||
const Dinero = require("dinero.js");
|
const Dinero = require("dinero.js");
|
||||||
const moment = require("moment-timezone");
|
const moment = require("moment-timezone");
|
||||||
var builder = require("xmlbuilder2");
|
var builder = require("xmlbuilder2");
|
||||||
const _ = require("lodash");
|
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
require("dotenv").config({
|
require("dotenv").config({
|
||||||
@@ -36,13 +35,11 @@ const ftpSetup = {
|
|||||||
exports.default = async (req, res) => {
|
exports.default = async (req, res) => {
|
||||||
// Only process if in production environment.
|
// Only process if in production environment.
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
res.sendStatus(403);
|
return res.sendStatus(403);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Only process if the appropriate token is provided.
|
// Only process if the appropriate token is provided.
|
||||||
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
||||||
res.sendStatus(401);
|
return res.sendStatus(401);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send immediate response and continue processing.
|
// Send immediate response and continue processing.
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const queries = require("../graphql-client/queries");
|
|||||||
const Dinero = require("dinero.js");
|
const Dinero = require("dinero.js");
|
||||||
const moment = require("moment-timezone");
|
const moment = require("moment-timezone");
|
||||||
var builder = require("xmlbuilder2");
|
var builder = require("xmlbuilder2");
|
||||||
const _ = require("lodash");
|
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
require("dotenv").config({
|
require("dotenv").config({
|
||||||
@@ -35,13 +34,11 @@ const ftpSetup = {
|
|||||||
exports.default = async (req, res) => {
|
exports.default = async (req, res) => {
|
||||||
// Only process if in production environment.
|
// Only process if in production environment.
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
res.sendStatus(403);
|
return res.sendStatus(403);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Only process if the appropriate token is provided.
|
// Only process if the appropriate token is provided.
|
||||||
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
||||||
res.sendStatus(401);
|
return res.sendStatus(401);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send immediate response and continue processing.
|
// Send immediate response and continue processing.
|
||||||
|
|||||||
@@ -29,13 +29,11 @@ const ftpSetup = {
|
|||||||
exports.default = async (req, res) => {
|
exports.default = async (req, res) => {
|
||||||
// Only process if in production environment.
|
// Only process if in production environment.
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
res.sendStatus(403);
|
return res.sendStatus(403);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Only process if the appropriate token is provided.
|
// Only process if the appropriate token is provided.
|
||||||
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
||||||
res.sendStatus(401);
|
return res.sendStatus(401);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send immediate response and continue processing.
|
// Send immediate response and continue processing.
|
||||||
|
|||||||
Reference in New Issue
Block a user