fix(rfid): lots of changes to the wrapper area
This commit is contained in:
@@ -12,20 +12,41 @@ import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
|||||||
import { db } from "../../../../../database/dbclient.js";
|
import { db } from "../../../../../database/dbclient.js";
|
||||||
import { rfidTags } from "../../../../../database/schema/rfidTags.js";
|
import { rfidTags } from "../../../../../database/schema/rfidTags.js";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
import { rfidReaders } from "../../../../../database/schema/rfidReaders.js";
|
||||||
|
|
||||||
export const wrapperStuff = async (tagData: any) => {
|
export const wrapperStuff = async (tagData: any) => {
|
||||||
console.log("WrapperTag", tagData[0].tag);
|
console.log("WrapperTag", tagData[0].tag);
|
||||||
|
|
||||||
|
const { error } = await tryCatch(
|
||||||
|
db
|
||||||
|
.update(rfidReaders)
|
||||||
|
.set({ lastTagScanned: tagData[0].tag })
|
||||||
|
.where(eq(rfidReaders.reader, tagData[0].reader))
|
||||||
|
);
|
||||||
|
if (error) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"rfid",
|
||||||
|
"rfid",
|
||||||
|
`${tagData[0].reader} encountered and error adding ${tagData[0].tag}.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (tagData.length != 1) {
|
if (tagData.length != 1) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"rfid",
|
"rfid",
|
||||||
"rfid",
|
"rfid",
|
||||||
`There are ${tagData.length} tags and this ${tagData[0].reader} only allows 1 tag to create a label.`
|
`There are ${tagData.length} tags and this ${
|
||||||
|
tagData[0].reader
|
||||||
|
} only allows 1 tag to create a label: tag ${tagData[0].tag}, ${
|
||||||
|
tagData[1].tag
|
||||||
|
}, ${tagData.length === 3 && tagData[2].tag}`
|
||||||
);
|
);
|
||||||
const tag = { ...tagData[0], runningNr: 0 };
|
const tag = { ...tagData[0], runningNr: 0 };
|
||||||
//tagStuff([tag]);
|
//tagStuff([tag]);
|
||||||
monitorChecks();
|
monitorChecks();
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (!tagData) {
|
if (!tagData) {
|
||||||
createLog("error", "rfid", "rfid", `No tagData was grabbed.`);
|
createLog("error", "rfid", "rfid", `No tagData was grabbed.`);
|
||||||
@@ -41,6 +62,21 @@ export const wrapperStuff = async (tagData: any) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const checkTag: any = tagdata;
|
const checkTag: any = tagdata;
|
||||||
|
|
||||||
|
if (checkTag.length === 0) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"rfid",
|
||||||
|
"rfid",
|
||||||
|
`${tagData[0].tag} is not currently registered to a line please validate the pallet and manually print.`
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message:
|
||||||
|
"There is no tag in the system please manually print..",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (checkTag[0]?.lastareaIn === "NeedsChecked") {
|
if (checkTag[0]?.lastareaIn === "NeedsChecked") {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
@@ -112,7 +148,7 @@ export const wrapperStuff = async (tagData: any) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const monitorErrorTags: any = [];
|
export const monitorErrorTags: any = [];
|
||||||
const monitorChecks = () => {
|
const monitorChecks = () => {
|
||||||
/**
|
/**
|
||||||
* If we have to check more than 10 tags in an hour send an email to alert everyone.
|
* If we have to check more than 10 tags in an hour send an email to alert everyone.
|
||||||
|
|||||||
Reference in New Issue
Block a user