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;
|
||||
35
lstV2/server/services/ocp/routes/lots/getLots.ts
Normal file
35
lstV2/server/services/ocp/routes/lots/getLots.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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 { getLots } from "../../controller/lots/lots.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: "/getlots",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c: any) => {
|
||||
const { data: lotData, error: lotError } = await tryCatch(getLots());
|
||||
apiHit(c, { endpoint: "/getlots" });
|
||||
if (lotError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error getting the printers",
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: lotData?.success,
|
||||
message: lotData?.message,
|
||||
data: lotData?.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
51
lstV2/server/services/ocp/routes/materials/currentPending.ts
Normal file
51
lstV2/server/services/ocp/routes/materials/currentPending.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
// 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 { pendingJobs } from "../../controller/materials/lotTransfer.js";
|
||||
import { format, formatDuration, intervalToDuration } from "date-fns";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Returns pending transfers",
|
||||
method: "get",
|
||||
path: "/pendingtransfers",
|
||||
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
apiHit(c, { endpoint: "/pendingtransfers" });
|
||||
|
||||
const pending = Array.from(pendingJobs.entries()).map(
|
||||
([runningNumber, job]) => {
|
||||
const duration = intervalToDuration({
|
||||
start: new Date(),
|
||||
end: job.scheduledFor,
|
||||
});
|
||||
return {
|
||||
runningNumber,
|
||||
lot: job.data?.lotNumber,
|
||||
newQty: job.newQty,
|
||||
consumeLot: job.consumeLot,
|
||||
scheduledFor: format(job.scheduledFor, "M/d/yyyy HH:mm"),
|
||||
remainingMs: formatDuration(duration, {
|
||||
format: ["hours", "minutes", "seconds"],
|
||||
}),
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
//console.log(pending);
|
||||
return c.json({
|
||||
success: true,
|
||||
message: "Current Pending trnasfers",
|
||||
data: [pending],
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
66
lstV2/server/services/ocp/routes/materials/lotTransfer.ts
Normal file
66
lstV2/server/services/ocp/routes/materials/lotTransfer.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
// 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 { lotMaterialTransfer } from "../../controller/materials/lotTransfer.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
const LotTransfer = z.object({
|
||||
runningNumber: z.number().openapi({ example: 1234 }),
|
||||
lotNumber: z.number().openapi({ example: 1235 }),
|
||||
originalAmount: z.number().openapi({ example: 457 }),
|
||||
level: z.number().openapi({ examples: [0.24, 0.5, 0.75, 0.95] }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Transfers a gaylord of material to provided lot",
|
||||
method: "post",
|
||||
path: "/materiallottransfer",
|
||||
request: {
|
||||
body: { content: { "application/json": { schema: LotTransfer } } },
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const hours = c.req.query("hours");
|
||||
const { data: bodyData, error: bodyError } = await tryCatch(
|
||||
c.req.json()
|
||||
);
|
||||
apiHit(c, { endpoint: "/materiallottransfer", lastBody: bodyData });
|
||||
|
||||
if (bodyError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "You are missing data",
|
||||
});
|
||||
}
|
||||
|
||||
const { data: transferMaterial, error: transferError } = await tryCatch(
|
||||
lotMaterialTransfer(bodyData)
|
||||
);
|
||||
|
||||
if (transferError) {
|
||||
//console.log(transferError);
|
||||
return c.json({
|
||||
success: false,
|
||||
message:
|
||||
"There was an error transfering the material to the next lot.",
|
||||
data: transferError,
|
||||
});
|
||||
}
|
||||
|
||||
console.log(transferMaterial);
|
||||
|
||||
return c.json({
|
||||
success: transferMaterial?.success,
|
||||
message: transferMaterial?.message,
|
||||
data: transferMaterial?.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
@@ -0,0 +1,43 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { printerCycle } from "../../controller/printers/printerCycle.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp:printers"],
|
||||
summary: "starts the printers cycling.",
|
||||
method: "get",
|
||||
path: "/startsprintercycle",
|
||||
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, error } = await tryCatch(printerCycle());
|
||||
apiHit(c, { endpoint: "/startsprintercycle" });
|
||||
const dataError: any = error;
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error in stopping the printer cycle",
|
||||
data: dataError?.data,
|
||||
});
|
||||
}
|
||||
const getData: any = data;
|
||||
return c.json({
|
||||
success: getData?.success,
|
||||
message: getData?.message,
|
||||
data: getData.data ?? [],
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
43
lstV2/server/services/ocp/routes/printers/autoLabelerStop.ts
Normal file
43
lstV2/server/services/ocp/routes/printers/autoLabelerStop.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { stopPrinterCycle } from "../../controller/printers/printerCycle.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp:printers"],
|
||||
summary: "Stops the printers cycling.",
|
||||
method: "get",
|
||||
path: "/stopprintercycle",
|
||||
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, error } = await tryCatch(stopPrinterCycle());
|
||||
apiHit(c, { endpoint: "/stopprintercycle" });
|
||||
const dataError: any = error;
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error in stopping the printer cycle",
|
||||
data: dataError?.data,
|
||||
});
|
||||
}
|
||||
const getData: any = data;
|
||||
return c.json({
|
||||
success: getData?.success,
|
||||
message: getData?.message,
|
||||
data: getData.data ?? [],
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
52
lstV2/server/services/ocp/routes/printers/getPritners.ts
Normal file
52
lstV2/server/services/ocp/routes/printers/getPritners.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
// 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 { getPrinters } from "../../controller/printers/getPrinters.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.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: "get",
|
||||
path: "/getprinters",
|
||||
//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: printData, error: printError } = await tryCatch(
|
||||
getPrinters()
|
||||
);
|
||||
apiHit(c, { endpoint: "/getprinters" });
|
||||
|
||||
if (printError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error getting the printers",
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: printData.success,
|
||||
message: printData.message,
|
||||
data: printData.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
43
lstV2/server/services/ocp/routes/printers/startCycle.ts
Normal file
43
lstV2/server/services/ocp/routes/printers/startCycle.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { printerCycle } from "../../controller/printers/printerCycle.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp:printers"],
|
||||
summary: "starts the printers cycling.",
|
||||
method: "get",
|
||||
path: "/startsprintercycle",
|
||||
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, error } = await tryCatch(printerCycle());
|
||||
apiHit(c, { endpoint: "/startsprintercycle" });
|
||||
const dataError: any = error;
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error in stopping the printer cycle",
|
||||
data: dataError?.data,
|
||||
});
|
||||
}
|
||||
const getData: any = data;
|
||||
return c.json({
|
||||
success: getData?.success,
|
||||
message: getData?.message,
|
||||
data: getData.data ?? [],
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
43
lstV2/server/services/ocp/routes/printers/stopCycle.ts
Normal file
43
lstV2/server/services/ocp/routes/printers/stopCycle.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { stopPrinterCycle } from "../../controller/printers/printerCycle.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp:printers"],
|
||||
summary: "Stops the printers cycling.",
|
||||
method: "get",
|
||||
path: "/stopprintercycle",
|
||||
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, error } = await tryCatch(stopPrinterCycle());
|
||||
apiHit(c, { endpoint: "/stopprintercycle" });
|
||||
const dataError: any = error;
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error in stopping the printer cycle",
|
||||
data: dataError?.data,
|
||||
});
|
||||
}
|
||||
const getData: any = data;
|
||||
return c.json({
|
||||
success: getData?.success,
|
||||
message: getData?.message,
|
||||
data: getData.data ?? [],
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
52
lstV2/server/services/ocp/routes/printers/updatePrinters.ts
Normal file
52
lstV2/server/services/ocp/routes/printers/updatePrinters.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
// 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 { updatePrinters } from "../../controller/printers/updatePrinters.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.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: "get",
|
||||
path: "/updateprinters",
|
||||
//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: printData, error: printError } = await tryCatch(
|
||||
updatePrinters()
|
||||
);
|
||||
apiHit(c, { endpoint: "/updateprinters" });
|
||||
|
||||
if (printError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error getting the printers",
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: printData.success,
|
||||
message: printData.message,
|
||||
data: printData.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
@@ -0,0 +1,57 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../../../globalUtils/routeDefs/responses.js";
|
||||
import { authMiddleware } from "../../../../auth/middleware/authMiddleware.js";
|
||||
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
|
||||
import { closeDyco } from "../../../controller/specialProcesses/dyco/plcConnection.js";
|
||||
import { apiHit } from "../../../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp:dyco"],
|
||||
summary: "Disconnect to the dyco.",
|
||||
method: "get",
|
||||
path: "/dycodisconnect",
|
||||
middleware: authMiddleware,
|
||||
description:
|
||||
"Use this when you just want to stop the entire thing due to an error or what not.",
|
||||
// request: {
|
||||
// body: {content: {"application/json": {schema: CreateLog}}},
|
||||
// },
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const body = await c.req.json();
|
||||
apiHit(c, { endpoint: `dycodisconnect` });
|
||||
// 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);
|
||||
// }
|
||||
|
||||
const { data, error } = await tryCatch(closeDyco());
|
||||
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error in connecting to dyco",
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
const getData: any = data;
|
||||
return c.json({
|
||||
success: getData?.success,
|
||||
message: getData?.message,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
@@ -0,0 +1,58 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../../../globalUtils/routeDefs/responses.js";
|
||||
import { authMiddleware } from "../../../../auth/middleware/authMiddleware.js";
|
||||
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
|
||||
import { dycoConnect } from "../../../controller/specialProcesses/dyco/plcConnection.js";
|
||||
import { apiHit } from "../../../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp:dyco"],
|
||||
summary: "Connects to the dyco.",
|
||||
method: "get",
|
||||
path: "/dycoconnect",
|
||||
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: `dycoconnect` });
|
||||
// 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);
|
||||
// }
|
||||
|
||||
const { data, error } = await tryCatch(dycoConnect());
|
||||
|
||||
const dataError: any = error;
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error in connecting to dyco",
|
||||
data: dataError?.data,
|
||||
});
|
||||
}
|
||||
const getData: any = data;
|
||||
return c.json({
|
||||
success: getData?.success,
|
||||
message: getData?.message,
|
||||
data: getData?.data ?? [],
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user