IO-594 Add AH Settings

This commit is contained in:
Patrick Fic
2021-07-21 13:11:51 -07:00
parent ae4a864533
commit 098754125b

View File

@@ -30,12 +30,14 @@ const ftpSetup = {
exports.default = async (req, res) => { exports.default = async (req, res) => {
//Query for the List of Bodyshop Clients. //Query for the List of Bodyshop Clients.
console.log("Starting Autohouse datapump request.");
const { bodyshops } = await client.request(queries.GET_AUTOHOUSE_SHOPS); const { bodyshops } = await client.request(queries.GET_AUTOHOUSE_SHOPS);
const allxmlsToUpload = []; const allxmlsToUpload = [];
const allErrors = []; const allErrors = [];
try {
for (const bodyshop of bodyshops) { for (const bodyshop of bodyshops) {
console.log("Starting extract for ", bodyshop.shopname);
const erroredJobs = []; const erroredJobs = [];
try { try {
const { jobs } = await client.request(queries.AUTOHOUSE_QUERY, { const { jobs } = await client.request(queries.AUTOHOUSE_QUERY, {
@@ -45,14 +47,18 @@ exports.default = async (req, res) => {
const autoHouseObject = { const autoHouseObject = {
AutoHouseExport: { AutoHouseExport: {
RepairOrder: jobs.map((j) => RepairOrder: jobs.map((j) =>
CreateRepairOrderTag({ ...j, bodyshop }, function ({ job, error }) { CreateRepairOrderTag(
{ ...j, bodyshop },
function ({ job, error }) {
erroredJobs.push({ job: job, error: error.toString() }); erroredJobs.push({ job: job, error: error.toString() });
}) }
)
), ),
}, },
}; };
console.log( console.log(
bodyshop.shopname,
"***Number of Failed jobs***: ", "***Number of Failed jobs***: ",
erroredJobs.length, erroredJobs.length,
JSON.stringify(erroredJobs.map((j) => j.job.ro_number)) JSON.stringify(erroredJobs.map((j) => j.job.ro_number))
@@ -71,8 +77,11 @@ exports.default = async (req, res) => {
"DDMMYYYY_HHMMSS" "DDMMYYYY_HHMMSS"
)}.xml`, )}.xml`,
}); });
console.log("Finished extract for shop ", bodyshop.shopname);
} catch (error) { } catch (error) {
//Error at the shop level. //Error at the shop level.
console.log("Error at shop level", bodyshop.shopname, error);
allErrors.push({ allErrors.push({
bodyshopid: bodyshop.id, bodyshopid: bodyshop.id,
imexshopid: bodyshop.imexshopid, imexshopid: bodyshop.imexshopid,
@@ -89,6 +98,9 @@ exports.default = async (req, res) => {
} }
let sftp = new Client(); let sftp = new Client();
sftp.on("error", (errors) =>
console.log("Error in FTP client", JSON.stringify(errors))
);
try { try {
//Connect to the FTP and upload all. //Connect to the FTP and upload all.
@@ -114,6 +126,9 @@ exports.default = async (req, res) => {
} }
res.sendStatus(200); res.sendStatus(200);
} catch (error) {
res.JSON(error).sendStatus(500);
}
}; };
const CreateRepairOrderTag = (job, errorCallback) => { const CreateRepairOrderTag = (job, errorCallback) => {