diff --git a/server/services/rfid/controller/stations/wrappers.ts b/server/services/rfid/controller/stations/wrappers.ts index 5aa3227..e87c765 100644 --- a/server/services/rfid/controller/stations/wrappers.ts +++ b/server/services/rfid/controller/stations/wrappers.ts @@ -12,20 +12,41 @@ import { tryCatch } from "../../../../globalUtils/tryCatch.js"; import { db } from "../../../../../database/dbclient.js"; import { rfidTags } from "../../../../../database/schema/rfidTags.js"; import { eq } from "drizzle-orm"; +import { rfidReaders } from "../../../../../database/schema/rfidReaders.js"; export const wrapperStuff = async (tagData: any) => { 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) { createLog( "error", "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 }; //tagStuff([tag]); monitorChecks(); + return; } else { if (!tagData) { createLog("error", "rfid", "rfid", `No tagData was grabbed.`); @@ -41,6 +62,21 @@ export const wrapperStuff = async (tagData: any) => { }; } 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") { createLog( "error", @@ -112,7 +148,7 @@ export const wrapperStuff = async (tagData: any) => { } }; -const monitorErrorTags: any = []; +export const monitorErrorTags: any = []; const monitorChecks = () => { /** * If we have to check more than 10 tags in an hour send an email to alert everyone.