test(rfid): more work on the rfid service

This commit is contained in:
2025-03-17 08:09:00 -05:00
parent ed11b2b26f
commit 21c374903b
3 changed files with 78 additions and 0 deletions

View File

@@ -31,6 +31,9 @@ export const wrapperStuff = async (tagData: TagData[]) => {
"rfid",
`${tagdata.tag}, Did not come from a line please check the pallet and manually print the label.`
);
// when we manually run again we want to make sure we read from the 3rd antenna this way we do not get the wrong info.
// more testing will need to be done on this.
}
// check if a running number exists

View File

@@ -0,0 +1,36 @@
import {db} from "../../../../../database/dbclient.js";
import {rfidTags} from "../../../../../database/schema/rfidTags.js";
import {createLog} from "../../../logger/logger.js";
export const manualTag = async (tag: string, area: string) => {
/**
* we only allow tags to be manually added from the wrappers
*/
// create the proper string
const number = tag.toString().padStart(9, "0");
const tagString = `ALPLA${number}`;
const newTag = {
tagHex: Buffer.from(tagString, "utf8").toString("hex").toUpperCase(),
tag: tagString,
lastRead: new Date(Date.now()),
counts: [{area: area, timesHere: 1}], //jsonb("counts").notNull(), //.default([{area: 1, timesHere: 5}]).notNull(),
lastareaIn: area,
antenna: 0,
tagStrength: -1,
};
try {
// insert the tag with the onConflict update the tag
const tag = await db.insert(rfidTags).values(newTag).returning({
tag: rfidTags.tag,
runningNumber: rfidTags.runningNumber,
counts: rfidTags.counts,
lastareaIn: rfidTags.lastareaIn,
});
createLog("info", "rfid", "rfid", `Tags were just added, and label printed.`);
// do the label thing here
return {success: true, message: `${tagString} was just added, and label printed.`, data: tag};
} catch (error) {
createLog("error", "rfid", "rfid", `${JSON.stringify(error)}`);
return {success: false, message: `Error creating a new tag`, data: error};
}
};