feat(notificaitons): fixed and corrections to get them working properly

This commit is contained in:
2025-04-04 17:12:48 -05:00
parent 99477bac19
commit a7818b4ca3
21 changed files with 888 additions and 633 deletions

View File

@@ -13,13 +13,13 @@ const notification = async (notifyData: any) => {
/**
* Pass the entire notification over
*/
createLog("info", "notify", "notify", `monitoring ${notifyData.name}`);
createLog("debug", "reprinting", "notify", `monitoring ${notifyData.name}`);
// validate if there are any emails.
if (notifyData.emails === "") {
createLog(
"error",
"notify",
"reprinting",
"notify",
`There are no emails set for ${notifyData.name}`
);
@@ -31,13 +31,14 @@ const notification = async (notifyData: any) => {
// set the time of getting the label
if (notifyData.timeType === "sec") {
timeCheck = `DATEADD(SECOND, -${notifyData.checkTime}, getdate()) `;
timeCheck = `DATEADD(SECOND, -${notifyData.checkInterval}, getdate()) `;
} else if (notifyData.timeType === "min") {
timeCheck = `DATEADD(MINUTE, -${notifyData.checkTime}, getdate()) `;
timeCheck = `DATEADD(MINUTE, -${notifyData.checkInterval}, getdate()) `;
}
let reprintQuery = `
SELECT
IdEtikettenHistorie,
IdArtikelvarianten as av,
ArtikelVariantenBez as alias,
LfdNr as runningNumber,
@@ -55,6 +56,7 @@ const notification = async (notifyData: any) => {
`;
//update the time check
reprintQuery = reprintQuery.replaceAll(
"DATEADD(SECOND, -30, getdate()) ",
timeCheck
@@ -66,10 +68,20 @@ const notification = async (notifyData: any) => {
query(reprintQuery, "Label Reprints")
);
if (labelError) {
createLog(
"error",
"reprinting",
"notify",
`Failed to get the labels: ${labelError}`
);
return;
}
if (labels.length > 0) {
//send the email :D
const emailSetup = {
emailTo: notifyData.emails,
email: notifyData.emails,
subject: "Alert! Label Reprinted",
template: "reprintLabels",
context: {
@@ -82,7 +94,7 @@ const notification = async (notifyData: any) => {
if (!sentEmail.success) {
createLog(
"error",
"notify",
"reprinting",
"notify",
"Failed to send email, will try again on next interval"
);
@@ -96,7 +108,6 @@ const notification = async (notifyData: any) => {
// };
// update the last time ran
const updateSettings = notifyData.notifiySettings;
const { data, error } = await tryCatch(
db
@@ -104,7 +115,7 @@ const notification = async (notifyData: any) => {
.set({
lastRan: sql`NOW()`,
notifiySettings: {
...updateSettings,
...notifyData.notifiySettings,
prodID: labels[0].IdEtikettenHistorie,
},
})