refactor(ocme): corrections to endpoints to work with ocnme as intneeded

This commit is contained in:
2025-03-25 07:54:58 -05:00
parent 73aa95a693
commit e6e1cecce3
8 changed files with 458 additions and 357 deletions

View File

@@ -10,7 +10,10 @@ type UpdateServerResponse = {
message: string; message: string;
}; };
export const updateServer = async (devApp: string, server: string | null): Promise<UpdateServerResponse> => { export const updateServer = async (
devApp: string,
server: string | null
): Promise<UpdateServerResponse> => {
const app = await getAppInfo(devApp); const app = await getAppInfo(devApp);
const serverInfo = await db const serverInfo = await db
.select() .select()
@@ -26,7 +29,8 @@ export const updateServer = async (devApp: string, server: string | null): Promi
); );
return { return {
success: false, success: false,
message: "Looks like you are missing the plant token or have entered an incorrect one please try again.", message:
"Looks like you are missing the plant token or have entered an incorrect one please try again.",
}; };
} }
@@ -156,7 +160,12 @@ export const updateServer = async (devApp: string, server: string | null): Promi
export async function processAllServers(devApp: string) { export async function processAllServers(devApp: string) {
const servers = await db.select().from(serverData); const servers = await db.select().from(serverData);
createLog("info", "lst", "serverUpdater", `Running the update on all servers`); createLog(
"info",
"lst",
"serverUpdater",
`Running the update on all servers`
);
let count = 1; let count = 1;
for (const server of servers) { for (const server of servers) {
try { try {
@@ -166,7 +175,12 @@ export async function processAllServers(devApp: string) {
//return {success: true, message: `${server.sName} was updated.`, data: updateToServer}; //return {success: true, message: `${server.sName} was updated.`, data: updateToServer};
} catch (error: any) { } catch (error: any) {
createLog("info", "lst", "serverUpdater", `Error updating ${server.sName}: ${error.message}`); createLog(
"info",
"lst",
"serverUpdater",
`Error updating ${server.sName}: ${error.message}`
);
//return {success: false, message: `Error updating ${server.sName}: ${error.message}`}; //return {success: false, message: `Error updating ${server.sName}: ${error.message}`};
} }
} }

View File

@@ -99,7 +99,7 @@ const updateBuildNumber = (appLock: string) => {
// Auto-commit changes // Auto-commit changes
execSync("git add package.json"); execSync("git add package.json");
execSync( execSync(
`git commit -m "build: bump build number to ${pkgJson.admConfig.build}"` `git commit -m "chore(release): bump build number to ${pkgJson.admConfig.build}"`
); );
} else { } else {
createLog( createLog(

View File

@@ -3,9 +3,14 @@ import axios from "axios";
export const ocmeInv = async (data: any) => { export const ocmeInv = async (data: any) => {
try { try {
const res = await axios.post( const res = await axios.post(
"http://usday1vms010:3250/api/v1/getLaneData", "http://usday1vms010:3250/api/v1/getlanedata",
{ lane: data.lane, laneType: data.laneType }, { lane: data.lane, laneType: data.laneType },
{headers: {"Content-Type": "application/json", Connection: "keep-alive"}} {
headers: {
"Content-Type": "application/json",
Connection: "keep-alive",
},
}
); );
// console.log(res.data.data); // console.log(res.data.data);

View File

@@ -7,17 +7,31 @@ import {eq} from "drizzle-orm";
export const getInfo = async () => { export const getInfo = async () => {
let ocmeInfo: any = []; let ocmeInfo: any = [];
try { try {
ocmeInfo = await db.select().from(ocmeData).where(eq(ocmeData.pickedUp, false)); ocmeInfo = await db
.select()
.from(ocmeData)
.where(eq(ocmeData.pickedUp, false));
// add in the time difference // add in the time difference
ocmeInfo = ocmeInfo.map((o: any) => { ocmeInfo = ocmeInfo.map((o: any) => {
const now = new Date(Date.now()); const now = new Date(Date.now());
const diff = differenceInMinutes(now, o.add_Date!); //const strippedDate = o.add_Date.replace("Z", "");
const diff = differenceInMinutes(now, o.add_Date);
return { ...o, waitingFor: diff }; return { ...o, waitingFor: diff };
}); });
createLog("info", "ocme", "ocme", `There are ${ocmeInfo.length} pallet(s) to be picked up.`); createLog(
"info",
"ocme",
"ocme",
`There are ${ocmeInfo.length} pallet(s) to be picked up.`
);
} catch (error) { } catch (error) {
createLog("error", "ocme", "ocme", "There was an error trying to retrive the ocmeInfo."); createLog(
"error",
"ocme",
"ocme",
"There was an error trying to retrive the ocmeInfo."
);
throw Error("There was an error trying to retrive the."); throw Error("There was an error trying to retrive the.");
} }

View File

@@ -11,10 +11,19 @@ import {serve} from "@hono/node-server";
import { createLog } from "../logger/logger.js"; import { createLog } from "../logger/logger.js";
import { db } from "../../../database/dbclient.js"; import { db } from "../../../database/dbclient.js";
import { settings } from "../../../database/schema/settings.js"; import { settings } from "../../../database/schema/settings.js";
import manualTrigger from "./route/triggerCamera.js";
const app = new OpenAPIHono(); const app = new OpenAPIHono();
const port = process.env.OCME_PORT; const port = process.env.OCME_PORT;
const routes = [getInfo, postRunningNr, postsscc, pickedup, getShipments, cycleCount] as const; const routes = [
getInfo,
postRunningNr,
postsscc,
pickedup,
getShipments,
cycleCount,
manualTrigger,
] as const;
const setting = await db.select().from(settings); const setting = await db.select().from(settings);
const isActive = setting.filter((n) => n.name === "ocmeService"); const isActive = setting.filter((n) => n.name === "ocmeService");
@@ -23,7 +32,10 @@ const appRoutes = routes.forEach((route) => {
}); });
app.all("/api/v1/*", (c) => { app.all("/api/v1/*", (c) => {
return c.json({success: false, message: "you have encounted an ocme route that dose not exist."}); return c.json({
success: false,
message: "you have encounted an ocme route that dose not exist.",
});
}); });
if (port && isActive[0]?.value === "1") { if (port && isActive[0]?.value === "1") {
serve( serve(
@@ -33,7 +45,12 @@ if (port && isActive[0]?.value === "1") {
hostname: "0.0.0.0", hostname: "0.0.0.0",
}, },
(info) => { (info) => {
createLog("info", "LST", "server", `Ocme section is listening on http://${info.address}:${info.port}`); createLog(
"info",
"LST",
"server",
`Ocme section is listening on http://${info.address}:${info.port}`
);
} }
); );
} }

View File

@@ -18,7 +18,7 @@ app.openapi(
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: {
@@ -48,10 +48,21 @@ app.openapi(
try { try {
const cycleData = await cycleCount(body, user); const cycleData = await cycleCount(body, user);
return c.json({success: true, message: `${body.lane} was just cycle counted.`, data: cycleData}, 200); return c.json(
{
success: true,
message: `${body.lane} was just cycle counted.`,
data: cycleData,
},
200
);
} catch (error) { } catch (error) {
return c.json( return c.json(
{success: false, message: `There was an error cycle counting ${body.lane}`, data: error}, {
success: false,
message: `There was an error cycle counting ${body.lane}`,
data: error,
},
400 400
); );
} }

View File

@@ -13,7 +13,7 @@ app.openapi(
tags: ["ocme"], tags: ["ocme"],
summary: "Post New running number to be picked up.", summary: "Post New running number to be picked up.",
method: "post", method: "post",
path: "/getshipmentpallets", path: "/GetShipmentPallets",
request: { request: {
body: { body: {
content: { content: {
@@ -42,7 +42,10 @@ app.openapi(
"application/json": { "application/json": {
schema: z.object({ schema: z.object({
success: z.boolean().openapi({ example: false }), success: z.boolean().openapi({ example: false }),
message: z.string().optional().openapi({example: "Internal Server error"}), message: z
.string()
.optional()
.openapi({ example: "Internal Server error" }),
data: z.array(z.object({})).optional().openapi({ example: [] }), data: z.array(z.object({})).optional().openapi({ example: [] }),
}), }),
}, },
@@ -73,9 +76,15 @@ app.openapi(
const data = await c.req.json(); const data = await c.req.json();
apiHit(c, { endpoint: "api/ocme/getshipmentpallets", lastBody: data }); apiHit(c, { endpoint: "api/ocme/getshipmentpallets", lastBody: data });
console.log;
if (!data.shipmentID) { if (!data.shipmentID) {
return c.json( return c.json(
{success: false, message: "You are missing the shipment id please try again.", data: []}, {
success: false,
message: "You are missing the shipment id please try again.",
data: [],
},
400 400
); );
} }
@@ -83,11 +92,22 @@ app.openapi(
const shiptmentData = await getShipmentPallets(data.shipmentID); const shiptmentData = await getShipmentPallets(data.shipmentID);
return c.json( return c.json(
{success: shiptmentData.success, message: shiptmentData.message, data: shiptmentData.data ?? []}, {
success: shiptmentData.success,
message: shiptmentData.message,
data: shiptmentData.data ?? [],
},
200 200
); );
} catch (error) { } catch (error) {
return c.json({success: false, message: "There was an error getting the shipment data.", data: error}, 400); return c.json(
{
success: false,
message: "There was an error getting the shipment data.",
data: error,
},
400
);
} }
} }
); );

View File

@@ -18,18 +18,28 @@ export const wrapperStuff = async (tagData: TagData[]) => {
tagStuff(tagData); tagStuff(tagData);
} else { } else {
const tagdata = await tagStuff(tagData); const tagdata = await tagStuff(tagData);
if (!tagData) {
createLog("error", "rfid", "rfid", `No tagData was grabbed.`);
}
/** /**
* we want to make sure this pallet came from a line as its last spot if not we need to have a manual check. * we want to make sure this pallet came from a line as its last spot if not we need to have a manual check.
*/ */
const station3 = tagdata.some((n: any) => n.lastareaIn.includes("line3")); if (
!Array.isArray(tagdata) &&
tagdata?.some((n: any) => n.lastareaIn.includes("line3"))
) {
createLog("error", "rfid", "rfid", `Data passed over is not an array.`);
return;
}
const station3 = tagdata; //?.some((n: any) => n.lastareaIn.includes("line3"));
if (!station3) { if (!station3) {
createLog( createLog(
"error", "error",
"rfid", "rfid",
"rfid", "rfid",
`${tagdata.tag}, Did not come from a line please check the pallet and manually print the label.` `${tagdata[0].tag}, Did not come from a line please check the pallet and manually print the label.`
); );
// when we manually run again we want to make sure we read from the 3rd antenna this way we do not get the wrong info. // when we manually run again we want to make sure we read from the 3rd antenna this way we do not get the wrong info.
@@ -38,9 +48,19 @@ export const wrapperStuff = async (tagData: TagData[]) => {
// check if a running number exists // check if a running number exists
if (station3.runningNumber) { if (station3.runningNumber) {
createLog("info", "rfid", "rfid", `Reprint label ${station3.runningNumber}`); createLog(
"info",
"rfid",
"rfid",
`Reprint label ${station3.runningNumber}`
);
} else { } else {
createLog("info", "rfid", "rfid", `A new labels will be created and linked to this ${tagdata.tag} tag`); createLog(
"info",
"rfid",
"rfid",
`A new labels will be created and linked to this ${tagdata.tag} tag`
);
} }
} }
}; };