IO-2921 CARSTAR Canada Requested Adjustments
Signed-off-by: Allan Carr <allan.carr@thinkimex.com>
This commit is contained in:
@@ -22,7 +22,6 @@ const ftpSetup = {
|
||||
serverHostKey: ["ssh-rsa", "ssh-dss", "rsa-sha2-256", "rsa-sha2-512", "ecdsa-sha2-nistp256", "ecdsa-sha2-nistp384"]
|
||||
}
|
||||
};
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
// Only process if in production environment.
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
@@ -30,16 +29,16 @@ exports.default = async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
//Query for the List of Bodyshop Clients.
|
||||
logger.log("chatter-start", "DEBUG", "api", null, null);
|
||||
const { bodyshops } = await client.request(queries.GET_CHATTER_SHOPS);
|
||||
|
||||
const specificShopIds = req.body.bodyshopIds; // ['uuid]
|
||||
const { start, end, skipUpload } = req.body; //YYYY-MM-DD
|
||||
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
||||
res.sendStatus(401);
|
||||
return;
|
||||
}
|
||||
//Query for the List of Bodyshop Clients.
|
||||
logger.log("chatter-start", "DEBUG", "api", null, null);
|
||||
const { bodyshops } = await client.request(queries.GET_CHATTER_SHOPS);
|
||||
const specificShopIds = req.body.bodyshopIds; // ['uuid]
|
||||
const { start, end, skipUpload } = req.body; //YYYY-MM-DD
|
||||
|
||||
const allcsvsToUpload = [];
|
||||
const allErrors = [];
|
||||
try {
|
||||
@@ -65,7 +64,7 @@ exports.default = async (req, res) => {
|
||||
};
|
||||
});
|
||||
|
||||
var ret = converter.json2csv(chatterObject, { emptyFieldValue: "" });
|
||||
const ret = converter.json2csv(chatterObject, { emptyFieldValue: "" });
|
||||
|
||||
allcsvsToUpload.push({
|
||||
count: chatterObject.length,
|
||||
@@ -100,10 +99,9 @@ exports.default = async (req, res) => {
|
||||
|
||||
if (skipUpload) {
|
||||
for (const csvObj of allcsvsToUpload) {
|
||||
fs.writeFileSync(`./logs/${csvObj.filename}`, csvObj.csv);
|
||||
fs.writeFile(`./logs/${csvObj.filename}`, csvObj.csv);
|
||||
}
|
||||
|
||||
res.json(allcsvsToUpload);
|
||||
sendServerEmail({
|
||||
subject: `Chatter Report ${moment().format("MM-DD-YY")}`,
|
||||
text: `Errors: ${allErrors.map((e) => JSON.stringify(e, null, 2))}
|
||||
@@ -114,10 +112,11 @@ exports.default = async (req, res) => {
|
||||
)}
|
||||
`
|
||||
});
|
||||
res.json(allcsvsToUpload);
|
||||
return;
|
||||
}
|
||||
|
||||
let sftp = new Client();
|
||||
const sftp = new Client();
|
||||
sftp.on("error", (errors) => logger.log("chatter-sftp-error", "ERROR", "api", null, { ...errors }));
|
||||
try {
|
||||
//Get the private key from AWS Secrets Manager.
|
||||
@@ -132,8 +131,6 @@ exports.default = async (req, res) => {
|
||||
const uploadResult = await sftp.put(Buffer.from(csvObj.xml), `/${csvObj.filename}`);
|
||||
logger.log("chatter-sftp-upload-result", "DEBUG", "api", null, { uploadResult });
|
||||
}
|
||||
|
||||
//***TODO Change filing naming when creating the cron job. IM_ShopInternalName_DDMMYYYY_HHMMSS.xml
|
||||
} catch (error) {
|
||||
logger.log("chatter-sftp-error", "ERROR", "api", null, { ...error });
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user