feat(lstv2 move): moved lstv2 into this app to keep them combined and easier to maintain
This commit is contained in:
68
lstV2/server/services/ocp/routes/labeling/bookIn.ts
Normal file
68
lstV2/server/services/ocp/routes/labeling/bookIn.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
|
||||
import { bookInLabel } from "../../controller/labeling/bookIn.js";
|
||||
import { createSSCC } from "../../../../globalUtils/createSSCC.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { commandLog } from "../../../../../database/schema/commandLog.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Manual bookin by running Number",
|
||||
method: "post",
|
||||
path: "/bookin",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const hours = c.req.query("hours");
|
||||
const { data: bodyData, error: bodyError } = await tryCatch(
|
||||
c.req.json()
|
||||
);
|
||||
apiHit(c, { endpoint: "/bookin", lastBody: bodyData });
|
||||
|
||||
if (bodyError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "You are missing data",
|
||||
});
|
||||
}
|
||||
|
||||
// get the sscc number
|
||||
const sscc = await createSSCC(bodyData.runningNr);
|
||||
|
||||
const { data: bookinLabel, error: bookInError } = await tryCatch(
|
||||
bookInLabel({ SSCC: sscc })
|
||||
);
|
||||
|
||||
if (bookInError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error booking in the label.",
|
||||
data: bookInError,
|
||||
});
|
||||
}
|
||||
|
||||
const newLabel: any = bookinLabel;
|
||||
//console.log(newLabel);
|
||||
|
||||
const { data: commandL, error: ce } = await tryCatch(
|
||||
db.insert(commandLog).values({
|
||||
commandUsed: "bookin",
|
||||
bodySent: bodyData,
|
||||
})
|
||||
);
|
||||
|
||||
return c.json({
|
||||
success: newLabel.success,
|
||||
message: newLabel.message,
|
||||
data: newLabel.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
38
lstV2/server/services/ocp/routes/labeling/getLabelRatio.ts
Normal file
38
lstV2/server/services/ocp/routes/labeling/getLabelRatio.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
import { getLabelRatio } from "../../controller/labeling/getLabelRatio.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Returns current active lots that are tech released",
|
||||
method: "get",
|
||||
path: "/labelratio",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const { data: labelData, error: labelError } = await tryCatch(
|
||||
getLabelRatio()
|
||||
);
|
||||
apiHit(c, { endpoint: "/labelratio" });
|
||||
|
||||
if (labelError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error getting the printers",
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: labelData.success,
|
||||
message: labelData.message,
|
||||
data: labelData.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
40
lstV2/server/services/ocp/routes/labeling/getLabels.ts
Normal file
40
lstV2/server/services/ocp/routes/labeling/getLabels.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { getLabels } from "../../controller/labeling/getLabels.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Returns current active lots that are tech released",
|
||||
method: "get",
|
||||
path: "/getlabels",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const hours = c.req.query("hours");
|
||||
const { data: labelData, error: labelError } = await tryCatch(
|
||||
getLabels(hours ?? "2")
|
||||
);
|
||||
apiHit(c, { endpoint: "/getLabels" });
|
||||
|
||||
if (labelError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error getting the printers",
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: labelData.success,
|
||||
message: labelData.message,
|
||||
count: labelData.count,
|
||||
data: labelData.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
53
lstV2/server/services/ocp/routes/labeling/manualPrint.ts
Normal file
53
lstV2/server/services/ocp/routes/labeling/manualPrint.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
import { manualLabelCreated } from "../../controller/labeling/labelRatio.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Manual print a label by line and printer name",
|
||||
method: "post",
|
||||
path: "/manualprintandfollow",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const hours = c.req.query("hours");
|
||||
const { data: bodyData, error: bodyError } = await tryCatch(
|
||||
c.req.json()
|
||||
);
|
||||
apiHit(c, { endpoint: "/manualprintandfollow", lastBody: bodyData });
|
||||
|
||||
if (bodyError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "You are missing data",
|
||||
});
|
||||
}
|
||||
|
||||
const { data: createLabel, error: labelError } = await tryCatch(
|
||||
labelingProcess({ line: bodyData.line })
|
||||
);
|
||||
manualLabelCreated();
|
||||
if (labelError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error creating the label.",
|
||||
data: labelError,
|
||||
});
|
||||
}
|
||||
|
||||
const newLabel: any = createLabel;
|
||||
return c.json({
|
||||
success: newLabel.success,
|
||||
message: newLabel.message,
|
||||
data: newLabel.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
71
lstV2/server/services/ocp/routes/labeling/manualPrintLog.ts
Normal file
71
lstV2/server/services/ocp/routes/labeling/manualPrintLog.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
// 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/labeling/manualLabelLog.js";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.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 { data: body, error } = await tryCatch(c.req.json());
|
||||
apiHit(c, { endpoint: "/manuallabellog", lastBody: body });
|
||||
if (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Missing Data.",
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
apiHit(c, { endpoint: `api/logger/logs/id` });
|
||||
try {
|
||||
//const data = {...body, add_user: user.username};
|
||||
const printLog: any = await manualPrint(body);
|
||||
return c.json(
|
||||
{
|
||||
success: printLog.success,
|
||||
message: printLog.message,
|
||||
data: printLog.data ?? [],
|
||||
},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error clearing the log.",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
38
lstV2/server/services/ocp/routes/labeling/resetLabelRatio.ts
Normal file
38
lstV2/server/services/ocp/routes/labeling/resetLabelRatio.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
import { getLabelRatio } from "../../controller/labeling/getLabelRatio.js";
|
||||
import { resetLabelRatio } from "../../controller/labeling/labelRatio.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Resets the label Ratio",
|
||||
method: "post",
|
||||
path: "/resetlabelratio",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const { data: labelData, error: labelError } = await tryCatch(
|
||||
resetLabelRatio()
|
||||
);
|
||||
apiHit(c, { endpoint: "/labelratio" });
|
||||
|
||||
if (labelError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error getting the printers",
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: labelData.success,
|
||||
message: labelData.message,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user