55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
|
import { addReader } from "../controller/addReader.js";
|
|
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
|
import type { User } from "../../../types/users.js";
|
|
import { verify } from "hono/jwt";
|
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
|
import { resetRatios } from "../controller/readerControl.js";
|
|
|
|
const app = new OpenAPIHono();
|
|
|
|
export const ReaderBody = z.object({
|
|
reader: z.string().openapi({ example: "wrapper1" }),
|
|
});
|
|
|
|
app.openapi(
|
|
createRoute({
|
|
tags: ["rfid"],
|
|
summary: "Resets the ratio on the reader",
|
|
method: "post",
|
|
path: "/resetRatio",
|
|
//middleware: authMiddleware,
|
|
//description: "Adding in a new reader to add to the network.",
|
|
request: {
|
|
body: { content: { "application/json": { schema: ReaderBody } } },
|
|
},
|
|
responses: responses(),
|
|
}),
|
|
async (c) => {
|
|
const body = await c.req.json();
|
|
apiHit(c, { endpoint: "/resetRatio", lastBody: body });
|
|
|
|
try {
|
|
const reset = await resetRatios(body.reader);
|
|
return c.json(
|
|
{
|
|
success: reset.success,
|
|
message: reset.message,
|
|
},
|
|
200
|
|
);
|
|
} catch (error) {
|
|
return c.json(
|
|
{
|
|
success: false,
|
|
message: `${body.name} encountered an error while trying to reset the readers ratio`,
|
|
},
|
|
400
|
|
);
|
|
}
|
|
}
|
|
);
|
|
|
|
export default app;
|