feat(ocme): cycle count added to db will add to front end later for users to inspect
This commit is contained in:
@@ -3,6 +3,10 @@ import { alplaStockInv } from "./cycleCount/alplaStockInventory.js";
|
|||||||
import { emptyCount } from "./cycleCount/emptyCycleCount.js";
|
import { emptyCount } from "./cycleCount/emptyCycleCount.js";
|
||||||
import { fullLaneCount } from "./cycleCount/fullLaneCycleCount.js";
|
import { fullLaneCount } from "./cycleCount/fullLaneCycleCount.js";
|
||||||
import { ocmeInv } from "./cycleCount/ocmeInventory.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 =
|
export const prepareLane =
|
||||||
"https://usday1prod.alpla.net/application/public/v1.1/Warehousing/PrepareLaneForInventory";
|
"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.
|
// 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;
|
return combineBoth;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,62 +10,62 @@ import { verify } from "hono/jwt";
|
|||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
const AddSetting = z.object({
|
const AddSetting = z.object({
|
||||||
lane: z.string().openapi({ example: "L064" }),
|
lane: z.string().openapi({ example: "L064" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
app.openapi(
|
app.openapi(
|
||||||
createRoute({
|
createRoute({
|
||||||
tags: ["ocme"],
|
tags: ["ocme"],
|
||||||
summary: "Cycle counts a lane based on the lane Alias",
|
summary: "Cycle counts a lane based on the lane Alias",
|
||||||
method: "post",
|
method: "post",
|
||||||
path: "/cycleCount",
|
path: "/cycleCount",
|
||||||
middleware: authMiddleware,
|
middleware: authMiddleware,
|
||||||
request: {
|
request: {
|
||||||
body: {
|
body: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": { schema: AddSetting },
|
"application/json": { schema: AddSetting },
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
responses: responses(),
|
||||||
},
|
}),
|
||||||
responses: responses(),
|
async (c) => {
|
||||||
}),
|
apiHit(c, { endpoint: "api/auth/register" });
|
||||||
async (c) => {
|
// make sure we have a vaid user being accessed thats really logged in
|
||||||
apiHit(c, { endpoint: "api/auth/register" });
|
const body = await c.req.json();
|
||||||
// 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] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
let user: User;
|
let user: User;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||||
user = payload.user as User;
|
user = payload.user as User;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return c.json({ message: "Unauthorized" }, 401);
|
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;
|
export default app;
|
||||||
|
|||||||
@@ -31,6 +31,15 @@ export const assignedPrinters = async () => {
|
|||||||
const printers: any = print.data ?? [];
|
const printers: any = print.data ?? [];
|
||||||
const lots: any = l.data.length === 0 ? [] : l.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++) {
|
for (let i = 0; i < printers.length; i++) {
|
||||||
// is the printer assinged in alplalabel online?
|
// is the printer assinged in alplalabel online?
|
||||||
const assigned = lots?.filter(
|
const assigned = lots?.filter(
|
||||||
|
|||||||
Reference in New Issue
Block a user