feat(rfid): new check to remove tags that have been at a line longer than 6 hours

This commit is contained in:
2025-08-21 05:18:49 -05:00
parent 846ac479b1
commit 0ba338d480
3 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import { and, lt, ne, sql } from "drizzle-orm";
import { db } from "../../../../database/dbclient.js";
import { rfidTags } from "../../../../database/schema/rfidTags.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
/**
* This will monitor tags that are older than 6hours and are still linked to a line.
* it will then remove the line from the last area in as we will asume it dose not exist.
*/
export const monitorRfidTags = async () => {
const { data, error } = await tryCatch(
db
.update(rfidTags)
.set({ lastareaIn: "miss scanned" })
.where(
and(
ne(rfidTags.lastareaIn, "wrapper1"), // not equal to 'wrapper1'
lt(rfidTags.lastRead, sql`NOW() - INTERVAL '6 hours'`) // older than 6 hours)
)
)
);
};