feat(lstv2 move): moved lstv2 into this app to keep them combined and easier to maintain
This commit is contained in:
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;
|
||||
Reference in New Issue
Block a user