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 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 allErrors = [];
try {
@@ -125,12 +125,24 @@ exports.default = async (req, res) => {
}
}
// for (const xmlObj of allxmlsToUpload) {
// fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml);
// }
if (skipUpload) {
for (const xmlObj of allxmlsToUpload) {
fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml);
}
// res.json(allxmlsToUpload);
// return;
res.json(allxmlsToUpload);
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();
sftp.on("error", (errors) =>
@@ -169,7 +181,7 @@ exports.default = async (req, res) => {
subject: `Autohouse Report ${moment().format("MM-DD-YY")}`,
text: `Errors: ${allErrors.map((e) => JSON.stringify(e, null, 2))}
Uploaded: ${JSON.stringify(
allxmlsToUpload.map((x) => x.filename),
allxmlsToUpload.map((x) => ({ filename: x.filename, count: x.count })),
null,
2
)}