Enable autohouse upload again.
This commit is contained in:
@@ -68,6 +68,10 @@ app.get("/test", async function (req, res) {
|
||||
"git rev-parse --short HEAD"
|
||||
);
|
||||
logger.log("test-api-status", "DEBUG", "api", { commit });
|
||||
sendEmail.sendServerEmail({
|
||||
subject: `API Check - ${process.env.NODE_ENV}`,
|
||||
text: `Server API check has come in. `,
|
||||
});
|
||||
res.status(200).send(`OK - ${commit}`);
|
||||
});
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ require("dotenv").config({
|
||||
let Client = require("ssh2-sftp-client");
|
||||
|
||||
const client = require("../graphql-client/graphql-client").client;
|
||||
const { sendServerEmail } = require("../email/sendemail");
|
||||
const AHDineroFormat = "0.00";
|
||||
const AhDateFormat = "MMDDYYYY";
|
||||
|
||||
@@ -112,16 +113,6 @@ exports.default = async (req, res) => {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//if (process.env.NODE_ENV !== "production") {
|
||||
for (const xmlObj of allxmlsToUpload) {
|
||||
fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml);
|
||||
}
|
||||
|
||||
res.json(allxmlsToUpload);
|
||||
return;
|
||||
// }
|
||||
|
||||
let sftp = new Client();
|
||||
sftp.on("error", (errors) =>
|
||||
logger.log("autohouse-sftp-error", "ERROR", "api", null, {
|
||||
@@ -155,7 +146,17 @@ exports.default = async (req, res) => {
|
||||
} finally {
|
||||
sftp.end();
|
||||
}
|
||||
|
||||
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) => x.filename),
|
||||
null,
|
||||
2
|
||||
)}
|
||||
`,
|
||||
});
|
||||
res.sendStatus(200);
|
||||
} catch (error) {
|
||||
res.status(200).json(error);
|
||||
@@ -682,13 +683,11 @@ const CreateCosts = (job) => {
|
||||
ticketTotalsByCostCenter[defaultCosts.LAM] || Dinero(),
|
||||
StructuralLaborTotalCost:
|
||||
ticketTotalsByCostCenter[defaultCosts.LAS] || Dinero(),
|
||||
ElectricalLaborTotalCost:
|
||||
ElectricalLaborTotalCost:
|
||||
ticketTotalsByCostCenter[defaultCosts.LAE] || Dinero(),
|
||||
FrameLaborTotalCost:
|
||||
ticketTotalsByCostCenter[defaultCosts.LAF] || Dinero(),
|
||||
GlassLaborTotalCost:
|
||||
ticketTotalsByCostCenter[defaultCosts.LAG] || Dinero(),
|
||||
DetailLaborTotalCost:
|
||||
FrameLaborTotalCost: ticketTotalsByCostCenter[defaultCosts.LAF] || Dinero(),
|
||||
GlassLaborTotalCost: ticketTotalsByCostCenter[defaultCosts.LAG] || Dinero(),
|
||||
DetailLaborTotalCost:
|
||||
ticketTotalsByCostCenter[defaultCosts.LAD] || Dinero(),
|
||||
PMTotalCost: billTotalsByCostCenters[defaultCosts.MAPA] || Dinero(),
|
||||
BMTotalCost: billTotalsByCostCenters[defaultCosts.MASH] || Dinero(),
|
||||
|
||||
@@ -18,6 +18,34 @@ let transporter = nodemailer.createTransport({
|
||||
SES: { ses, aws },
|
||||
});
|
||||
|
||||
exports.sendServerEmail = async function ({ subject, text }) {
|
||||
try {
|
||||
transporter.sendMail(
|
||||
{
|
||||
from: `ImEX Online API - ${process.env.NODE_ENV} <noreply@imex.online>`,
|
||||
to: ["patrick@snapt.ca"],
|
||||
subject: subject,
|
||||
text: text,
|
||||
ses: {
|
||||
// optional extra arguments for SendRawEmail
|
||||
Tags: [
|
||||
{
|
||||
Name: "tag_name",
|
||||
Value: "tag_value",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
(err, info) => {
|
||||
console.log(err || info);
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
logger.log("server-email-failure", "error", null, null, error);
|
||||
}
|
||||
};
|
||||
|
||||
exports.sendEmail = async (req, res) => {
|
||||
logger.log("send-email", "DEBUG", req.user.email, null, {
|
||||
from: `${req.body.from.name} <${req.body.from.address}>`,
|
||||
|
||||
Reference in New Issue
Block a user