feat(quality): addpallet and cycle pallets added
This commit is contained in:
34
server/services/quality/route/getRequest.ts
Normal file
34
server/services/quality/route/getRequest.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { getRequest } from "../controller/getRequests.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["quality"],
|
||||
summary: "Returns all pallets requested",
|
||||
method: "get",
|
||||
path: "/getrequest",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const { data, error } = await tryCatch(getRequest());
|
||||
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error getting the printers",
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: data.success,
|
||||
message: data.message,
|
||||
data: data.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
73
server/services/quality/route/postNewRequest.ts
Normal file
73
server/services/quality/route/postNewRequest.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { getRequest } from "../controller/getRequests.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||
import { addNewPallet } from "../controller/addNewPallet.js";
|
||||
import { verify } from "hono/jwt";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
const Body = z.object({
|
||||
runningNr: z.number().openapi({ example: 1528 }),
|
||||
moveTo: z.string().openapi({ example: "rework" }),
|
||||
});
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["quality"],
|
||||
summary: "Returns all pallets requested",
|
||||
method: "post",
|
||||
path: "/newrequest",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: Body },
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const authHeader = c.req.header("Authorization");
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
const user: any = payload.user;
|
||||
|
||||
const { data: b, error: e } = await tryCatch(c.req.json());
|
||||
|
||||
if (e) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Missing Data",
|
||||
});
|
||||
}
|
||||
const body: any = b;
|
||||
// console.log(body);
|
||||
// if (!body.runningNr) {
|
||||
// return c.json({
|
||||
// success: false,
|
||||
// message: "Missing mandatory data.",
|
||||
// });
|
||||
// }
|
||||
|
||||
const { data, error } = await tryCatch(
|
||||
addNewPallet(body, user?.username)
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error adding the new pallet",
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: data?.success,
|
||||
message: data?.message,
|
||||
data: data?.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user