diff --git a/server/services/ocme/controller/cycleCount.ts b/server/services/ocme/controller/cycleCount.ts index 5ec4890..7eae5ea 100644 --- a/server/services/ocme/controller/cycleCount.ts +++ b/server/services/ocme/controller/cycleCount.ts @@ -3,6 +3,10 @@ import { alplaStockInv } from "./cycleCount/alplaStockInventory.js"; import { emptyCount } from "./cycleCount/emptyCycleCount.js"; import { fullLaneCount } from "./cycleCount/fullLaneCycleCount.js"; import { ocmeInv } from "./cycleCount/ocmeInventory.js"; +import { ocmeCycleCounts } from "../../../../database/schema/ocmeCycleCounts.js"; +import { db } from "../../../../database/dbclient.js"; +import { tryCatch } from "../../../globalUtils/tryCatch.js"; +import { createLog } from "../../logger/logger.js"; export const prepareLane = "https://usday1prod.alpla.net/application/public/v1.1/Warehousing/PrepareLaneForInventory"; @@ -74,6 +78,33 @@ export const cycleCount = async (lane: any, user: User) => { } // store in the db so we have a record.... for later when we fully randomize and automate this. + const postCount = { + laneId: ocme[0].alpla_laneID, + warehouseName: "", + laneName: alplaStock[0].alpla_laneDescription, + good: !combineBoth.every( + (s) => !s.info.includes("Validate") || !s.info.includes("sent") + ), + cycleCount: combineBoth, + add_User: user.username, + }; + + const { data, error } = await tryCatch( + db.insert(ocmeCycleCounts).values(postCount) + ); + + if (error) { + createLog( + "error", + "lst", + "ocme", + `There was an error entering the cycle count data: ${error}` + ); + } + + if (data) { + createLog("info", "lst", "ocme", `Cycle Count data just added.`); + } return combineBoth; }; diff --git a/server/services/ocme/route/cycleCount.ts b/server/services/ocme/route/cycleCount.ts index 903f750..7326da7 100644 --- a/server/services/ocme/route/cycleCount.ts +++ b/server/services/ocme/route/cycleCount.ts @@ -10,62 +10,62 @@ import { verify } from "hono/jwt"; const app = new OpenAPIHono({ strict: false }); const AddSetting = z.object({ - lane: z.string().openapi({ example: "L064" }), + lane: z.string().openapi({ example: "L064" }), }); app.openapi( - createRoute({ - tags: ["ocme"], - summary: "Cycle counts a lane based on the lane Alias", - method: "post", - path: "/cycleCount", - middleware: authMiddleware, - request: { - body: { - content: { - "application/json": { schema: AddSetting }, + createRoute({ + tags: ["ocme"], + summary: "Cycle counts a lane based on the lane Alias", + method: "post", + path: "/cycleCount", + middleware: authMiddleware, + request: { + body: { + content: { + "application/json": { schema: AddSetting }, + }, + }, }, - }, - }, - responses: responses(), - }), - async (c) => { - apiHit(c, { endpoint: "api/auth/register" }); - // make sure we have a vaid user being accessed thats really logged in - const body = await c.req.json(); + responses: responses(), + }), + async (c) => { + apiHit(c, { endpoint: "api/auth/register" }); + // make sure we have a vaid user being accessed thats really logged in + const body = await c.req.json(); - const authHeader = c.req.header("Authorization"); + const authHeader = c.req.header("Authorization"); - const token = authHeader?.split("Bearer ")[1] || ""; - let user: User; + 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) { - return c.json({ message: "Unauthorized" }, 401); + try { + const payload = await verify(token, process.env.JWT_SECRET!); + user = payload.user as User; + } catch (error) { + return c.json({ message: "Unauthorized" }, 401); + } + + try { + const cycleData = await cycleCount(body, user); + return c.json( + { + success: true, + message: `${body.lane} was just cycle counted.`, + data: cycleData, + }, + 200 + ); + } catch (error) { + return c.json( + { + success: false, + message: `There was an error cycle counting ${body.lane}`, + data: error, + }, + 400 + ); + } } - - try { - const cycleData = await cycleCount(body, user); - return c.json( - { - success: true, - message: `${body.lane} was just cycle counted.`, - data: cycleData, - }, - 200 - ); - } catch (error) { - return c.json( - { - success: false, - message: `There was an error cycle counting ${body.lane}`, - data: error, - }, - 400 - ); - } - } ); export default app; diff --git a/server/services/ocp/utils/checkAssignments.ts b/server/services/ocp/utils/checkAssignments.ts index be420be..127e215 100644 --- a/server/services/ocp/utils/checkAssignments.ts +++ b/server/services/ocp/utils/checkAssignments.ts @@ -31,6 +31,15 @@ export const assignedPrinters = async () => { const printers: any = print.data ?? []; const lots: any = l.data.length === 0 ? [] : l.data; + if (!lots) { + createLog( + "error", + "lst", + "ocp", + `There was an error getting the lots: ${lots.message}` + ); + return; + } for (let i = 0; i < printers.length; i++) { // is the printer assinged in alplalabel online? const assigned = lots?.filter(