test(rfid): more work on the rfid service
This commit is contained in:
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