Merged in feature/2021-07-23 (pull request #147)

IO-594 Add AH Settings
This commit is contained in:
Patrick Fic
2021-07-21 20:18:47 +00:00

View File

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