test(rfid): more work on the rfid service
This commit is contained in:
@@ -31,6 +31,9 @@ export const wrapperStuff = async (tagData: TagData[]) => {
|
||||
"rfid",
|
||||
`${tagdata.tag}, Did not come from a line please check the pallet and manually print the label.`
|
||||
);
|
||||
|
||||
// when we manually run again we want to make sure we read from the 3rd antenna this way we do not get the wrong info.
|
||||
// more testing will need to be done on this.
|
||||
}
|
||||
|
||||
// check if a running number exists
|
||||
|
||||
36
server/services/rfid/controller/tags/manualTag.ts
Normal file
36
server/services/rfid/controller/tags/manualTag.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import {db} from "../../../../../database/dbclient.js";
|
||||
import {rfidTags} from "../../../../../database/schema/rfidTags.js";
|
||||
import {createLog} from "../../../logger/logger.js";
|
||||
|
||||
export const manualTag = async (tag: string, area: string) => {
|
||||
/**
|
||||
* we only allow tags to be manually added from the wrappers
|
||||
*/
|
||||
// create the proper string
|
||||
const number = tag.toString().padStart(9, "0");
|
||||
const tagString = `ALPLA${number}`;
|
||||
const newTag = {
|
||||
tagHex: Buffer.from(tagString, "utf8").toString("hex").toUpperCase(),
|
||||
tag: tagString,
|
||||
lastRead: new Date(Date.now()),
|
||||
counts: [{area: area, timesHere: 1}], //jsonb("counts").notNull(), //.default([{area: 1, timesHere: 5}]).notNull(),
|
||||
lastareaIn: area,
|
||||
antenna: 0,
|
||||
tagStrength: -1,
|
||||
};
|
||||
try {
|
||||
// insert the tag with the onConflict update the tag
|
||||
const tag = await db.insert(rfidTags).values(newTag).returning({
|
||||
tag: rfidTags.tag,
|
||||
runningNumber: rfidTags.runningNumber,
|
||||
counts: rfidTags.counts,
|
||||
lastareaIn: rfidTags.lastareaIn,
|
||||
});
|
||||
createLog("info", "rfid", "rfid", `Tags were just added, and label printed.`);
|
||||
// do the label thing here
|
||||
return {success: true, message: `${tagString} was just added, and label printed.`, data: tag};
|
||||
} catch (error) {
|
||||
createLog("error", "rfid", "rfid", `${JSON.stringify(error)}`);
|
||||
return {success: false, message: `Error creating a new tag`, data: error};
|
||||
}
|
||||
};
|
||||
39
server/services/rfid/route/manualTagEnter.ts
Normal file
39
server/services/rfid/route/manualTagEnter.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
//http://usday1vms006:4000/api/v1/zebra/wrapper1
|
||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
||||
import {manualTag} from "../controller/tags/manualTag.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const RequestBody = z.object({
|
||||
tagNumber: z.string().openapi({example: "2541"}),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["rfid"],
|
||||
summary: "Post a manual Tag",
|
||||
method: "post",
|
||||
path: "/manualtag",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
body: {content: {"application/json": {schema: RequestBody}}},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const body =
|
||||
(await c.req.json()) ??
|
||||
c.json({success: false, message: `Please check that you are sending over a json object`}, 400);
|
||||
|
||||
try {
|
||||
const tag = await manualTag(body.tag, body.area);
|
||||
return c.json({success: tag.success, message: tag.message, data: tag.data}, 200);
|
||||
} catch (error) {
|
||||
return c.json({success: true, message: `There was an error with entering a new tag`, error}, 400);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user