feat(ocp): create and book in plus dyco controller implemented

This commit is contained in:
2025-03-26 22:07:19 -05:00
parent 878e650e62
commit 7a1a4773e7
23 changed files with 1233 additions and 40 deletions

View File

@@ -1,8 +1,8 @@
import axios from "axios";
import {createLog} from "../../logger/logger.js";
import {db} from "../../../../database/dbclient.js";
import {rfidReaders} from "../../../../database/schema/rfidReaders.js";
import {eq} from "drizzle-orm";
import { createLog } from "../../logger/logger.js";
import { db } from "../../../../database/dbclient.js";
import { rfidReaders } from "../../../../database/schema/rfidReaders.js";
import { eq } from "drizzle-orm";
const authData = btoa("admin:Zebra123!");
let token: string;
@@ -12,10 +12,18 @@ export const readTags = async (reader: string) => {
/**
* Start the read for x seconds then auto stop it
*/
const readers = await db.select().from(rfidReaders).where(eq(rfidReaders.active, true));
createLog("info", "rfid", "rfid", `Read was just triggered from ${reader}`);
const readers = await db
.select()
.from(rfidReaders)
.where(eq(rfidReaders.active, true));
if (readers.length === 0) {
createLog("error", "rfid", "rfid", `There are no active readers right now maybe one forgot to be activated`);
createLog(
"error",
"rfid",
"rfid",
`There are no active readers right now maybe one forgot to be activated`
);
return;
}
// get the auth token
@@ -23,7 +31,7 @@ export const readTags = async (reader: string) => {
try {
const res = await axios.get(`https://${ip}/cloud/localRestLogin`, {
headers: {Authorization: `Basic ${authData}`},
headers: { Authorization: `Basic ${authData}` },
});
token = res.data.message;
// start the read
@@ -47,7 +55,7 @@ const startRead = async () => {
`https://${ip}/cloud/start`,
{},
{
headers: {Authorization: `Bearer ${token}`},
headers: { Authorization: `Bearer ${token}` },
}
);
@@ -67,7 +75,12 @@ const startRead = async () => {
startRead();
}, 1000);
}
createLog("error", "rfid", "rfid", `There was an error Starting the read: ${error.response.data.message}`);
createLog(
"error",
"rfid",
"rfid",
`There was an error Starting the read: ${error.response.data.message}`
);
}
};
const stopRead = async () => {
@@ -76,10 +89,15 @@ const stopRead = async () => {
`https://${ip}/cloud/stop`,
{},
{
headers: {Authorization: `Bearer ${token}`},
headers: { Authorization: `Bearer ${token}` },
}
);
} catch (error: any) {
createLog("error", "rfid", "rfid", `There was an error Stopping the read: ${error.response.data.message}`);
createLog(
"error",
"rfid",
"rfid",
`There was an error Stopping the read: ${error.response.data.message}`
);
}
};

View File

@@ -1,5 +1,5 @@
import {station3Tags} from "./stations/station3.js";
import {wrapperStuff} from "./stations/wrappers.js";
import { station3Tags } from "./stations/station3.js";
import { wrapperStuff } from "./stations/wrappers.js";
export type TagData = {
tagHex: string;
@@ -8,6 +8,7 @@ export type TagData = {
timeStamp: Date;
antenna: number;
tagStrength: number;
lastareaIn?: string;
};
export const tagData = async (data: TagData[]) => {
/**