release/2024-11-01 - Misc fixes

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-10-29 10:53:09 -07:00
parent 3f247a9227
commit 42f1d6fa13
12 changed files with 108 additions and 61 deletions

View File

@@ -39,8 +39,8 @@ exports.default = async function ReloadCdkMakes(req, res) {
const deleteResult = await client
.setHeaders({ Authorization: BearerToken })
.request(queries.DELETE_ALL_DMS_VEHICLES, {});
console.log("🚀 ~ file: cdk-get-makes.js ~ line 53 ~ deleteResult", deleteResult);
// logger.logger.debug("🚀 ~ file: cdk-get-makes.js ~ line 53 ~ deleteResult", { deleteResult });
//Insert the new ones.
const insertResult = await client.setHeaders({ Authorization: BearerToken }).request(queries.INSERT_DMS_VEHICLES, {
@@ -59,6 +59,7 @@ exports.default = async function ReloadCdkMakes(req, res) {
cdk_dealerid,
count: newList.length
});
res.sendStatus(200);
} catch (error) {
logger.log("cdk-replace-makes-models-error", "ERROR", req.user.email, null, {

View File

@@ -21,7 +21,7 @@ const getImage = async (imageUrl) => {
// Log the email in the database
const logEmail = async (req, email) => {
try {
const insertresult = await client.request(queries.INSERT_EMAIL_AUDIT, {
await client.request(queries.INSERT_EMAIL_AUDIT, {
email: {
to: email.to,
cc: email.cc,
@@ -34,13 +34,13 @@ const logEmail = async (req, email) => {
status: "Sent"
}
});
console.log(insertresult);
} catch (error) {
logger.log("email-log-error", "error", req.user.email, null, {
logger.log("email-log-error", "error", req?.user?.email, null, {
from: `${req.body.from.name} <${req.body.from.address}>`,
to: req.body.to,
cc: req.body.cc,
subject: req.body.subject
to: req?.body?.to,
cc: req?.body?.cc,
subject: req?.body?.subject,
email
// info,
});
}
@@ -70,12 +70,11 @@ const sendServerEmail = async ({ subject, text }) => {
}
},
(err, info) => {
console.log(err || info);
logger.log("server-email-failure", err ? "error" : "debug", null, null, { message: err || info });
}
);
} catch (error) {
console.log(error);
logger.log("server-email-failure", "error", null, null, error);
logger.log("server-email-failure", "error", null, null, { error });
}
};
@@ -88,8 +87,7 @@ const sendProManagerWelcomeEmail = async ({ to, subject, html }) => {
html
});
} catch (error) {
console.log(error);
logger.log("server-email-failure", "error", null, null, error);
logger.log("server-email-failure", "error", null, null, { error });
}
};
@@ -108,12 +106,12 @@ const sendTaskEmail = async ({ to, subject, type = "text", html, text, attachmen
attachments: attachments || null
},
(err, info) => {
console.log(err || info);
// (message, type, user, record, meta
logger.log("server-email", err ? "error" : "debug", null, null, { message: err || info });
}
);
} catch (error) {
console.log(error);
logger.log("server-email-failure", "error", null, null, error);
logger.log("server-email-failure", "error", null, null, { error });
}
};
@@ -184,9 +182,8 @@ const sendEmail = async (req, res) => {
}
},
(err, info) => {
console.log(err || info);
if (info) {
logger.log("send-email-success", "DEBUG", req.user.email, null, {
logger.log("send-email-success", "DEBUG", req?.user?.email, null, {
from: `${req.body.from.name} <${req.body.from.address}>`,
replyTo: req.body.ReplyTo.Email,
to: req.body.to,
@@ -205,7 +202,7 @@ const sendEmail = async (req, res) => {
success: true //response: info
});
} else {
logger.log("send-email-failure", "ERROR", req.user.email, null, {
logger.log("send-email-failure", "ERROR", req?.user?.email, null, {
from: `${req.body.from.name} <${req.body.from.address}>`,
replyTo: req.body.ReplyTo.Email,
to: req.body.to,
@@ -290,7 +287,9 @@ ${body.bounce?.bouncedRecipients.map(
`
},
(err, info) => {
console.log("***", err || info);
logger.log("sns-error", err ? "error" : "debug", "api", null, {
message: err ? JSON.stringify(error) : info
});
}
);
}

View File

@@ -18,10 +18,10 @@ const tasksEmailQueue = taskEmailQueue();
const tasksEmailQueueCleanup = async () => {
try {
// Example async operation
console.log("Performing Tasks Email Reminder process cleanup...");
// console.log("Performing Tasks Email Reminder process cleanup...");
await new Promise((resolve) => tasksEmailQueue.destroy(() => resolve()));
} catch (err) {
console.error("Tasks Email Reminder process cleanup failed:", err);
// console.error("Tasks Email Reminder process cleanup failed:", err);
}
};

View File

@@ -10,8 +10,9 @@ const logger = require("../utils/logger");
const taskEmailQueue = () =>
new Queue(
(taskIds, cb) => {
console.log("Processing reminds for taskIds: ", taskIds.join(", "));
logger.log("Processing reminds for taskIds: ", "silly", null, null, {
taskIds: taskIds?.join(", ")
});
// Set the remind_at_sent to the current time.
const now = moment().toISOString();

View File

@@ -269,10 +269,14 @@ const sendNotification = async (req, res) => {
})
.then((response) => {
// Response is a message ID string.
console.log("Successfully sent message:", response);
logger.log("Successfully sent message:", "debug", req?.user?.email, null, {
response
});
})
.catch((error) => {
console.log("Error sending message:", error);
logger.log("Successfully sent message:", "error", req?.user?.email, null, {
error
});
});
res.sendStatus(200);

View File

@@ -46,7 +46,9 @@ async function JobCostingMulti(req, res) {
const BearerToken = req.BearerToken;
const client = req.userGraphQLClient;
logger.log("job-costing-multi-start", "DEBUG", req.user.email, jobids, null);
logger.log("job-costing-multi-start", "DEBUG", req?.user?.email, null, {
jobids
});
try {
const resp = await client
@@ -244,7 +246,8 @@ async function JobCostingMulti(req, res) {
data: ret
});
} catch (error) {
logger.log("job-costing-multi-error", "ERROR", req.user.email, [jobids], {
logger.log("job-costing-multi-error", "ERROR", req?.user?.email, null, {
jobids,
message: error.message,
stack: error.stack
});
@@ -282,7 +285,12 @@ function GenerateCostingData(job) {
if (val.mod_lbr_ty) {
const laborProfitCenter = val.profitcenter_labor || defaultProfits[val.mod_lbr_ty] || "Unknown";
if (laborProfitCenter === "Unknown") console.log("Unknown type", val.line_desc, val.mod_lbr_ty);
if (laborProfitCenter === "Unknown") {
logger.log("job-costing unknown type", "debug", null, null, {
line_desc: val.line_desc,
mod_lbr_ty: val.mod_lbr_ty
});
}
const rateName = `rate_${(val.mod_lbr_ty || "").toLowerCase()}`;
@@ -349,10 +357,21 @@ function GenerateCostingData(job) {
if (val.part_type && val.part_type !== "PAE" && val.part_type !== "PAS" && val.part_type !== "PASL") {
const partsProfitCenter = val.profitcenter_part || defaultProfits[val.part_type] || "Unknown";
if (partsProfitCenter === "Unknown") console.log("Unknown type", val.line_desc, val.part_type);
if (partsProfitCenter === "Unknown" || !partsProfitCenter) {
logger.log(
partsProfitCenter === "Unknown"
? "job-costing unknown type"
: "Unknown cost/profit center mapping for parts.",
"debug",
null,
null,
{
line_desc: val.line_desc,
part_type: val.part_type
}
);
}
if (!partsProfitCenter)
console.log("Unknown cost/profit center mapping for parts.", val.line_desc, val.part_type);
let partsAmount = Dinero({
amount: val.act_price_before_ppc
? Math.round(val.act_price_before_ppc * 100)
@@ -409,10 +428,21 @@ function GenerateCostingData(job) {
if (val.part_type && val.part_type !== "PAE" && (val.part_type === "PAS" || val.part_type === "PASL")) {
const partsProfitCenter = val.profitcenter_part || defaultProfits[val.part_type] || "Unknown";
if (partsProfitCenter === "Unknown") console.log("Unknown type", val.line_desc, val.part_type);
if (partsProfitCenter === "Unknown" || !partsProfitCenter) {
logger.log(
partsProfitCenter === "Unknown"
? "job-costing unknown type"
: "job-costing Unknown cost/profit center mapping for sublet",
"debug",
null,
null,
{
line_desc: val.line_desc,
part_type: val.part_type
}
);
}
if (!partsProfitCenter)
console.log("Unknown cost/profit center mapping for sublet.", val.line_desc, val.part_type);
const partsAmount = Dinero({
amount: Math.round((val.act_price || 0) * 100)
})
@@ -444,7 +474,10 @@ function GenerateCostingData(job) {
const partsProfitCenter = val.profitcenter_part || getAdditionalCostCenter(val, defaultProfits) || "Unknown";
if (partsProfitCenter === "Unknown") {
console.log("Unknown type", val.line_desc, val.part_type);
logger.log("job-costing unknown type", "debug", null, null, {
line_desc: val.line_desc,
part_type: val.part_type
});
}
const partsAmount = Dinero({
amount: Math.round((val.act_price || 0) * 100)

View File

@@ -26,7 +26,7 @@ exports.totalsSsu = async function (req, res) {
const BearerToken = req.BearerToken;
const client = req.userGraphQLClient;
logger.log("job-totals-ssu-USA", "DEBUG", req.user.email, id, null);
logger.log("job-totals-ssu-USA", "DEBUG", req?.user?.email, id);
try {
const job = await client.setHeaders({ Authorization: BearerToken }).request(queries.GET_JOB_BY_PK, {
@@ -47,7 +47,7 @@ exports.totalsSsu = async function (req, res) {
res.status(200).send();
} catch (error) {
logger.log("job-totals-ssu-USA-error", "ERROR", req.user.email, id, {
logger.log("job-totals-ssu-USA-error", "ERROR", req?.user?.email, id, {
jobid: id,
error
});
@@ -84,12 +84,10 @@ async function Totals(req, res) {
const logger = req.logger;
const client = req.userGraphQLClient;
logger.log("job-totals-USA", "DEBUG", req.user.email, job.id, {
logger.log("job-totals-ssu-USA", "DEBUG", req.user.email, job.id, {
jobid: job.id
});
logger.log("job-totals-ssu-USA", "DEBUG", req.user.email, id, null);
await AutoAddAtsIfRequired({ job, client });
try {
@@ -961,7 +959,9 @@ function CalculateTaxesTotals(job, otherTotals) {
}
}
} catch (error) {
console.error("Key with issue", key);
logger.log("job-totals-USA Key with issue", "error", null, null, {
key
});
}
});
@@ -1026,7 +1026,9 @@ function CalculateTaxesTotals(job, otherTotals) {
totalTaxByTier[taxTierKey] = totalTaxByTier[taxTierKey].add(taxAmountToAdd);
}
} catch (error) {
console.error("PFP Calculation error", error);
logger.log("job-totals-USA - PFP Calculation Error", "error", null, null, {
error
});
}
});

View File

@@ -16,7 +16,11 @@ const validateFirebaseIdTokenMiddleware = async (req, res, next) => {
(!req.headers.authorization || !req.headers.authorization.startsWith("Bearer ")) &&
!(req.cookies && req.cookies.__session)
) {
console.error("Unauthorized attempt. No authorization provided.");
logger.log("api-authorization-call", "warn", req?.user?.email, null, {
type: "unauthorized",
path: req.path,
body: req.body
});
return res.status(403).send("Unauthorized");
}
@@ -32,10 +36,10 @@ const validateFirebaseIdTokenMiddleware = async (req, res, next) => {
idToken = req.cookies.__session;
} else {
// No cookie
console.error("Unauthorized attempt. No cookie provided.");
logger.log("api-unauthorized-call", "WARN", null, null, {
req,
type: "no-cookie"
logger.log("api-unauthorized-call", "warn", null, null, {
type: "unauthorized",
path: req.path,
body: req.body
});
return res.status(403).send("Unauthorized");
@@ -47,11 +51,11 @@ const validateFirebaseIdTokenMiddleware = async (req, res, next) => {
req.user = decodedIdToken;
next();
} catch (error) {
logger.log("api-unauthorized-call", "WARN", null, null, {
logger.log("api-unauthorized-call", "warn", null, null, {
path: req.path,
body: req.body,
type: "unauthroized",
type: "unauthorized",
...error
});

View File

@@ -45,12 +45,12 @@ exports.payall = async function (req, res) {
const path = diffParser(diff);
if (diff.op === "add") {
console.log(Object.keys(diff.val));
// console.log(Object.keys(diff.val));
if (typeof diff.val === "object" && Object.keys(diff.val).length > 1) {
//Multiple values to add.
Object.keys(diff.val).forEach((key) => {
console.log("Hours", diff.val[key][Object.keys(diff.val[key])[0]]);
console.log("Rate", Object.keys(diff.val[key])[0]);
// console.log("Hours", diff.val[key][Object.keys(diff.val[key])[0]]);
// console.log("Rate", Object.keys(diff.val[key])[0]);
ticketsToInsert.push({
task_name: "Pay All",
jobid: job.id,

View File

@@ -49,7 +49,7 @@ exports.job = async (req, res) => {
if (bucketId) {
load.productionTotal[bucketId].count = load.productionTotal[bucketId].count + 1;
} else {
console.log("Uh oh, this job doesn't fit in a bucket!", item);
// console.log("Uh oh, this job doesn't fit in a bucket!", item);
}
});
@@ -254,7 +254,7 @@ const CalculateLoad = (currentLoad, buckets, jobsIn, jobsOut) => {
if (bucketId) {
newLoad[bucketId].count = newLoad[bucketId].count + 1;
} else {
console.log("[Util Arr Job]Uh oh, this job doesn't fit in a bucket!", job);
// console.log("[Util Arr Job]Uh oh, this job doesn't fit in a bucket!", job);
}
});
@@ -263,10 +263,10 @@ const CalculateLoad = (currentLoad, buckets, jobsIn, jobsOut) => {
if (bucketId) {
newLoad[bucketId].count = newLoad[bucketId].count - 1;
if (newLoad[bucketId].count < 0) {
console.log("***ERROR: NEGATIVE LOAD Bucket =>", bucketId, job);
// console.log("***ERROR: NEGATIVE LOAD Bucket =>", bucketId, job);
}
} else {
console.log("[Util Out Job]Uh oh, this job doesn't fit in a bucket!", job);
// console.log("[Util Out Job]Uh oh, this job doesn't fit in a bucket!", job);
}
});

View File

@@ -39,7 +39,7 @@ const processor = async (req, res) => {
}
});
} catch (error) {
console.log("error", error);
// console.log("error", error);
res.status(400).send(error);
}
};

View File

@@ -6,10 +6,11 @@ const client = require("../graphql-client/graphql-client").client;
const emailer = require("../email/sendemail");
const moment = require("moment-timezone");
const converter = require("json-2-csv");
const logger = require("../utils/logger");
exports.taskHandler = async (req, res) => {
try {
const { bodyshopid, query, variables, text, to, subject, timezone } = req.body;
const { query, variables, text, to, subject, timezone } = req.body;
//Check the variables to see if they are an object.
Object.keys(variables).forEach((key) => {
@@ -32,8 +33,10 @@ exports.taskHandler = async (req, res) => {
text,
attachments: [{ filename: "query.csv", content: csv }]
})
.catch((err) => {
console.error("Errors sending CSV Email.");
.catch((error) => {
logger.log("Tasks - Error sending CSV EMAIL", "error", req?.user?.email, null, {
error
});
});
return res.status(200).send(csv);