test(rfid): more rfid work and tested working

This commit is contained in:
2025-04-17 18:42:29 -05:00
parent af8d53cac1
commit a68a3ba640
5 changed files with 62 additions and 16 deletions

View File

@@ -0,0 +1,14 @@
import OpenOrders from "@/components/logistics/warehouse/openOrders";
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/(logistics)/openOrders/")({
component: RouteComponent,
});
function RouteComponent() {
return (
<div className="m-5 w-11/12 h-9/10">
<OpenOrders />
</div>
);
}

View File

@@ -1,6 +1,17 @@
import { format } from "date-fns"; import { addHours, format } from "date-fns";
export const fixTime = (date: any) => { export const fixTime = (date: any) => {
const strippedDate = date.replace("Z", ""); // Remove Z if (!date) return;
return format(strippedDate, "MM/dd/yyyy hh:mm a"); // const strippedDate = date?.replace("Z", ""); // Remove Z
//return format(strippedDate, "MM/dd/yyyy hh:mm a");
const rawDate = new Date(date).toISOString();
const offsetMinutes = new Date().getTimezoneOffset(); // in minutes
const offsetHours =
-offsetMinutes / 60 >= 0 ? offsetMinutes / 60 : -offsetMinutes / 60;
return format(
addHours(rawDate, offsetHours).toISOString(),
"MM/dd/yyyy hh:mm a"
);
}; };

View File

@@ -7,7 +7,6 @@ import { eq } from "drizzle-orm";
const authData = btoa("admin:Zebra123!"); const authData = btoa("admin:Zebra123!");
let token: string; let token: string;
let ip: string; let ip: string;
export const readTags = async (reader: string) => { export const readTags = async (reader: string) => {
/** /**
* Start the read for x seconds then auto stop it * Start the read for x seconds then auto stop it
@@ -30,7 +29,7 @@ export const readTags = async (reader: string) => {
ip = readers.find((r) => r.reader === reader)?.readerIP as string; ip = readers.find((r) => r.reader === reader)?.readerIP as string;
// start the read // start the read
startRead(); startRead(reader, ip);
// start the read // start the read
}; };
@@ -50,7 +49,7 @@ const getReaderToken = async () => {
} }
}; };
const startRead = async () => { const startRead = async (reader: string, ip: string) => {
await getReaderToken(); await getReaderToken();
try { try {
const res = await axios.put( const res = await axios.put(
@@ -65,17 +64,17 @@ const startRead = async () => {
if (res.status === 200) { if (res.status === 200) {
setTimeout(() => { setTimeout(() => {
stopRead(); stopRead(reader, ip);
}, 2 * 1000); }, 5 * 1000);
} }
// stop after 5 seconds // stop after 5 seconds
} catch (error: any) { } catch (error: any) {
if (error.response?.data.code === 3) { if (error.response?.data.code === 3) {
stopRead(); stopRead(reader, ip);
setTimeout(() => { setTimeout(() => {
startRead(); startRead(reader, ip);
}, 1000); }, 2 * 1000);
} }
createLog( createLog(
"error", "error",
@@ -86,7 +85,7 @@ const startRead = async () => {
} }
}; };
export const stopRead = async () => { export const stopRead = async (reader: string, ip: string) => {
await getReaderToken(); await getReaderToken();
try { try {
const res = await axios.put( const res = await axios.put(
@@ -101,7 +100,7 @@ export const stopRead = async () => {
"error", "error",
"rfid", "rfid",
"rfid", "rfid",
`There was an error Stopping the read: ${JSON.stringify(error)}` `There was an error Stopping the read on ${reader}`
); );
} }
}; };

View File

@@ -3,11 +3,32 @@
* Phase 2 we will generate a label to be reprinted at staion 4 * Phase 2 we will generate a label to be reprinted at staion 4
*/ */
import { eq } from "drizzle-orm";
import { db } from "../../../../../database/dbclient.js";
import { rfidReaders } from "../../../../../database/schema/rfidReaders.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { createLog } from "../../../logger/logger.js"; import { createLog } from "../../../logger/logger.js";
import type { TagData } from "../tagData.js"; import type { TagData } from "../tagData.js";
import { tagStuff } from "../tags/crudTag.js"; import { tagStuff } from "../tags/crudTag.js";
export const station3Tags = async (tagData: TagData[]) => { export const station3Tags = async (tagData: TagData[]) => {
/**
* Add the new tag to the reader so we know waht was really here
*/
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 addeding ${tagData[0].tag}.`
);
}
createLog( createLog(
"info", "info",
"rfid", "rfid",

View File

@@ -67,18 +67,19 @@ export const wrapperStuff = async (tagData: any) => {
"rfid", "rfid",
`${tagData[0].tag}, Did not come from a line please check the pallet and manually print the label.` `${tagData[0].tag}, Did not come from a line please check the pallet and manually print the label.`
); );
tagStuff(tagData);
monitorChecks(); monitorChecks();
return { return {
success: false, success: false,
message: `${tagData[0].tag}, Did not come from a line please check the pallet and manually print the label.`, message: `${tagData[0].tag}, Did not come from a line please check the pallet and manually print the label.`,
}; };
} }
if (lines[0].runningNumber) { if (lines[0]?.runningNumber) {
createLog( createLog(
"info", "info",
"rfid", "rfid",
"rfid", "rfid",
`Reprint label ${lines[0].runningNumber}` `Reprint label ${lines[0]?.runningNumber}`
); );
} else { } else {
createLog( createLog(
@@ -88,7 +89,7 @@ export const wrapperStuff = async (tagData: any) => {
`A new label will be created and linked to this ${tagData[0].tag} tag` `A new label will be created and linked to this ${tagData[0].tag} tag`
); );
const lineNum = parseInt( const lineNum = parseInt(
checkTag[0]?.lastareaIn.repalceAll("line3", "") checkTag[0]?.lastareaIn.replace("line3.", "")
); );
createLog( createLog(
"info", "info",