refactor(rfid): ratio resets implemeneted

This commit is contained in:
2025-07-14 12:36:36 -05:00
parent 4923b3c698
commit a7f8e39bac
5 changed files with 159 additions and 29 deletions

View File

@@ -6,6 +6,7 @@ import { eq, sql } from "drizzle-orm";
import { db } from "../../../../database/dbclient.js";
import { rfidReaders } from "../../../../database/schema/rfidReaders.js";
import { createLog } from "../../logger/logger.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
export const newHeartBeat = async (reader: string) => {
/**
@@ -79,6 +80,36 @@ export const badRead = async (reader: string) => {
}
};
export const resetRatios = async (reader: string) => {
const { error } = await tryCatch(
db
.update(rfidReaders)
.set({
goodReads: 0,
badReads: 0,
})
.where(eq(rfidReaders.reader, reader))
);
if (error) {
createLog(
"error",
"rfid",
"rfid",
`${reader} encountered an error resetting the data.`
);
return {
success: false,
message: `${reader} encountered an error resetting the data.`,
};
}
createLog("info", "rfid", "rfid", `${reader} just had the tag data reset.`);
return {
success: true,
message: `${reader} just had the tag data reset.`,
};
};
export const goodRead = async (reader: string) => {
/**
* When we have a bad read we want to make sure the reader shows this was well.