Update error handling for autohouse.

This commit is contained in:
Patrick Fic
2022-06-28 08:34:34 -07:00
parent 4582c493ee
commit fbcf2b559e

View File

@@ -39,7 +39,7 @@ exports.default = async (req, res) => {
const { bodyshops } = await client.request(queries.GET_AUTOHOUSE_SHOPS); const { bodyshops } = await client.request(queries.GET_AUTOHOUSE_SHOPS);
const specificShopIds = req.body.bodyshopIds; // ['uuid] const specificShopIds = req.body.bodyshopIds; // ['uuid]
const { start, end } = req.body; //YYYY-MM-DD const { start, end, skipUpload } = req.body; //YYYY-MM-DD
const allxmlsToUpload = []; const allxmlsToUpload = [];
const allErrors = []; const allErrors = [];
try { try {
@@ -125,12 +125,24 @@ exports.default = async (req, res) => {
} }
} }
// for (const xmlObj of allxmlsToUpload) { if (skipUpload) {
// fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml); for (const xmlObj of allxmlsToUpload) {
// } fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml);
}
// res.json(allxmlsToUpload); res.json(allxmlsToUpload);
// return; sendServerEmail({
subject: `Autohouse Report ${moment().format("MM-DD-YY")}`,
text: `Errors: ${allErrors.map((e) => JSON.stringify(e, null, 2))}
Uploaded: ${JSON.stringify(
allxmlsToUpload.map((x) => ({ filename: x.filename, count: x.count })),
null,
2
)}
`,
});
return;
}
let sftp = new Client(); let sftp = new Client();
sftp.on("error", (errors) => sftp.on("error", (errors) =>
@@ -169,7 +181,7 @@ exports.default = async (req, res) => {
subject: `Autohouse Report ${moment().format("MM-DD-YY")}`, subject: `Autohouse Report ${moment().format("MM-DD-YY")}`,
text: `Errors: ${allErrors.map((e) => JSON.stringify(e, null, 2))} text: `Errors: ${allErrors.map((e) => JSON.stringify(e, null, 2))}
Uploaded: ${JSON.stringify( Uploaded: ${JSON.stringify(
allxmlsToUpload.map((x) => x.filename), allxmlsToUpload.map((x) => ({ filename: x.filename, count: x.count })),
null, null,
2 2
)} )}