feat(ocp): added in service plus manual print log
This commit is contained in:
20
server/services/ocp/controller/manualLabelLog.ts
Normal file
20
server/services/ocp/controller/manualLabelLog.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import {db} from "../../../../database/dbclient.js";
|
||||
import {manualPrinting} from "../../../../database/schema/ocpManualPrint.js";
|
||||
|
||||
export const manualPrint = async (data: any) => {
|
||||
/**
|
||||
* add the reason we did a manual print.
|
||||
*/
|
||||
|
||||
const manualPrintData = {
|
||||
line: data.line,
|
||||
printReason: data.printReason,
|
||||
initials: data.initials,
|
||||
additionalComments: data?.additionalComments,
|
||||
add_user: "lst",
|
||||
};
|
||||
|
||||
try {
|
||||
const manualPrint = await db.insert(manualPrinting).values(manualPrintData);
|
||||
} catch (error) {}
|
||||
};
|
||||
22
server/services/ocp/ocpService.ts
Normal file
22
server/services/ocp/ocpService.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import {OpenAPIHono} from "@hono/zod-openapi";
|
||||
|
||||
// routes
|
||||
import manualLabelLog from "./routes/manualPrintLog.js";
|
||||
|
||||
import {db} from "../../../database/dbclient.js";
|
||||
import {settings} from "../../../database/schema/settings.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const routes = [manualLabelLog] as const;
|
||||
const setting = await db.select().from(settings);
|
||||
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
app.route("/ocp", route);
|
||||
});
|
||||
|
||||
app.all("/ocp/*", (c) => {
|
||||
return c.json({success: false, message: "You have encounters a ocp route that dose not exist."});
|
||||
});
|
||||
|
||||
export default app;
|
||||
56
server/services/ocp/routes/manualPrintLog.ts
Normal file
56
server/services/ocp/routes/manualPrintLog.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
// an external way to creating logs
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
||||
import type {User} from "../../../types/users.js";
|
||||
import {verify} from "hono/jwt";
|
||||
import {manualPrint} from "../controller/manualLabelLog.js";
|
||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
||||
|
||||
const app = new OpenAPIHono({strict: false});
|
||||
const CreateLog = z.object({
|
||||
line: z.string().openapi({example: "info"}),
|
||||
initials: z.string().openapi({example: "server"}),
|
||||
printReason: z.string().openapi({example: "This is a new log posted"}),
|
||||
additionalComments: z.string().optional().openapi({example: "Some reason why we did this."}),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Post the log for manaulprinting.",
|
||||
method: "post",
|
||||
path: "/manuallabellog",
|
||||
//middleware: authMiddleware,
|
||||
//description: "This might be a temp soltuin during the transtion between versions",
|
||||
request: {
|
||||
body: {content: {"application/json": {schema: CreateLog}}},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const body = await c.req.json();
|
||||
apiHit(c, {endpoint: `api/logger/logs/id`});
|
||||
// const authHeader = c.req.header("Authorization");
|
||||
|
||||
// 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) {
|
||||
// console.log(error);
|
||||
// return c.json({message: "Unauthorized"}, 401);
|
||||
// }
|
||||
|
||||
try {
|
||||
//const data = {...body, add_user: user.username};
|
||||
await manualPrint(body);
|
||||
return c.json({success: true, message: "Manual Print was added.", data: []}, 200);
|
||||
} catch (error) {
|
||||
return c.json({success: false, message: "There was an error clearing the log.", data: error}, 400);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
52
server/services/ocp/routes/printLabel.ts
Normal file
52
server/services/ocp/routes/printLabel.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
// an external way to creating logs
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
||||
|
||||
const app = new OpenAPIHono({strict: false});
|
||||
const CreateLog = z.object({
|
||||
line: z.string().openapi({example: "info"}),
|
||||
initials: z.string().openapi({example: "server"}),
|
||||
printReason: z.string().openapi({example: "This is a new log posted"}),
|
||||
additionalComments: z.string().optional().openapi({example: "Some reason why we did this."}),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Prints a label.",
|
||||
method: "post",
|
||||
path: "/printlabel",
|
||||
//middleware: authMiddleware,
|
||||
//description: "This might be a temp soltuin during the transtion between versions",
|
||||
request: {
|
||||
body: {content: {"application/json": {schema: CreateLog}}},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const body = await c.req.json();
|
||||
apiHit(c, {endpoint: `api/logger/logs/id`});
|
||||
// const authHeader = c.req.header("Authorization");
|
||||
|
||||
// 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) {
|
||||
// console.log(error);
|
||||
// return c.json({message: "Unauthorized"}, 401);
|
||||
// }
|
||||
|
||||
try {
|
||||
//const data = {...body, add_user: user.username};
|
||||
|
||||
return c.json({success: true, message: "Label was printed.", data: []}, 200);
|
||||
} catch (error) {
|
||||
return c.json({success: false, message: "There was an error printing a label.", data: error}, 400);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user