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"]
|
serverHostKey: ["ssh-rsa", "ssh-dss", "rsa-sha2-256", "rsa-sha2-512", "ecdsa-sha2-nistp256", "ecdsa-sha2-nistp384"]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.default = async (req, res) => {
|
exports.default = async (req, res) => {
|
||||||
// Only process if in production environment.
|
// Only process if in production environment.
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
@@ -30,16 +29,16 @@ exports.default = async (req, res) => {
|
|||||||
return;
|
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) {
|
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
||||||
res.sendStatus(401);
|
res.sendStatus(401);
|
||||||
return;
|
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 allcsvsToUpload = [];
|
||||||
const allErrors = [];
|
const allErrors = [];
|
||||||
try {
|
try {
|
||||||
@@ -65,7 +64,7 @@ exports.default = async (req, res) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
var ret = converter.json2csv(chatterObject, { emptyFieldValue: "" });
|
const ret = converter.json2csv(chatterObject, { emptyFieldValue: "" });
|
||||||
|
|
||||||
allcsvsToUpload.push({
|
allcsvsToUpload.push({
|
||||||
count: chatterObject.length,
|
count: chatterObject.length,
|
||||||
@@ -100,10 +99,9 @@ exports.default = async (req, res) => {
|
|||||||
|
|
||||||
if (skipUpload) {
|
if (skipUpload) {
|
||||||
for (const csvObj of allcsvsToUpload) {
|
for (const csvObj of allcsvsToUpload) {
|
||||||
fs.writeFileSync(`./logs/${csvObj.filename}`, csvObj.csv);
|
fs.writeFile(`./logs/${csvObj.filename}`, csvObj.csv);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json(allcsvsToUpload);
|
|
||||||
sendServerEmail({
|
sendServerEmail({
|
||||||
subject: `Chatter Report ${moment().format("MM-DD-YY")}`,
|
subject: `Chatter 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))}
|
||||||
@@ -114,10 +112,11 @@ exports.default = async (req, res) => {
|
|||||||
)}
|
)}
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
|
res.json(allcsvsToUpload);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sftp = new Client();
|
const sftp = new Client();
|
||||||
sftp.on("error", (errors) => logger.log("chatter-sftp-error", "ERROR", "api", null, { ...errors }));
|
sftp.on("error", (errors) => logger.log("chatter-sftp-error", "ERROR", "api", null, { ...errors }));
|
||||||
try {
|
try {
|
||||||
//Get the private key from AWS Secrets Manager.
|
//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}`);
|
const uploadResult = await sftp.put(Buffer.from(csvObj.xml), `/${csvObj.filename}`);
|
||||||
logger.log("chatter-sftp-upload-result", "DEBUG", "api", null, { uploadResult });
|
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) {
|
} catch (error) {
|
||||||
logger.log("chatter-sftp-error", "ERROR", "api", null, { ...error });
|
logger.log("chatter-sftp-error", "ERROR", "api", null, { ...error });
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user