refactor(rfid): ratio resets implemeneted
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user