feat(ocme): cycle count added to db will add to front end later for users to inspect
This commit is contained in:
@@ -10,62 +10,62 @@ import { verify } from "hono/jwt";
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
const AddSetting = z.object({
|
||||
lane: z.string().openapi({ example: "L064" }),
|
||||
lane: z.string().openapi({ example: "L064" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Cycle counts a lane based on the lane Alias",
|
||||
method: "post",
|
||||
path: "/cycleCount",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: AddSetting },
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Cycle counts a lane based on the lane Alias",
|
||||
method: "post",
|
||||
path: "/cycleCount",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: AddSetting },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
apiHit(c, { endpoint: "api/auth/register" });
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const body = await c.req.json();
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
apiHit(c, { endpoint: "api/auth/register" });
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const body = await c.req.json();
|
||||
|
||||
const authHeader = c.req.header("Authorization");
|
||||
const authHeader = c.req.header("Authorization");
|
||||
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
let user: User;
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
let user: User;
|
||||
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
user = payload.user as User;
|
||||
} catch (error) {
|
||||
return c.json({ message: "Unauthorized" }, 401);
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
user = payload.user as User;
|
||||
} catch (error) {
|
||||
return c.json({ message: "Unauthorized" }, 401);
|
||||
}
|
||||
|
||||
try {
|
||||
const cycleData = await cycleCount(body, user);
|
||||
return c.json(
|
||||
{
|
||||
success: true,
|
||||
message: `${body.lane} was just cycle counted.`,
|
||||
data: cycleData,
|
||||
},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: `There was an error cycle counting ${body.lane}`,
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const cycleData = await cycleCount(body, user);
|
||||
return c.json(
|
||||
{
|
||||
success: true,
|
||||
message: `${body.lane} was just cycle counted.`,
|
||||
data: cycleData,
|
||||
},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: `There was an error cycle counting ${body.lane}`,
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
|
||||
Reference in New Issue
Block a user