refactor(ocme): corrections to endpoints to work with ocnme as intneeded
This commit is contained in:
@@ -1,173 +1,187 @@
|
||||
import {spawn} from "child_process";
|
||||
import {getAppInfo} from "../globalUtils/appInfo.js";
|
||||
import {db} from "../../database/dbclient.js";
|
||||
import {serverData} from "../../database/schema/serverData.js";
|
||||
import {eq, sql} from "drizzle-orm";
|
||||
import {createLog} from "../services/logger/logger.js";
|
||||
import { spawn } from "child_process";
|
||||
import { getAppInfo } from "../globalUtils/appInfo.js";
|
||||
import { db } from "../../database/dbclient.js";
|
||||
import { serverData } from "../../database/schema/serverData.js";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { createLog } from "../services/logger/logger.js";
|
||||
|
||||
type UpdateServerResponse = {
|
||||
success: boolean;
|
||||
message: string;
|
||||
success: boolean;
|
||||
message: string;
|
||||
};
|
||||
|
||||
export const updateServer = async (devApp: string, server: string | null): Promise<UpdateServerResponse> => {
|
||||
const app = await getAppInfo(devApp);
|
||||
const serverInfo = await db
|
||||
export const updateServer = async (
|
||||
devApp: string,
|
||||
server: string | null
|
||||
): Promise<UpdateServerResponse> => {
|
||||
const app = await getAppInfo(devApp);
|
||||
const serverInfo = await db
|
||||
.select()
|
||||
.from(serverData)
|
||||
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
||||
|
||||
if (serverInfo.length === 0) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"serverUpdater",
|
||||
`Looks like you are missing the plant token or have entered an incorrect one please try again.`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: "Looks like you are missing the plant token or have entered an incorrect one please try again.",
|
||||
};
|
||||
}
|
||||
if (serverInfo.length === 0) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"serverUpdater",
|
||||
`Looks like you are missing the plant token or have entered an incorrect one please try again.`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message:
|
||||
"Looks like you are missing the plant token or have entered an incorrect one please try again.",
|
||||
};
|
||||
}
|
||||
|
||||
if (serverInfo[0].isUpgrading) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"serverUpdater",
|
||||
`Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`,
|
||||
};
|
||||
}
|
||||
if (serverInfo[0].isUpgrading) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"serverUpdater",
|
||||
`Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`,
|
||||
};
|
||||
}
|
||||
|
||||
const scriptPath = `${process.env.DEVFOLDER}\\server\\scripts\\update.ps1 `;
|
||||
const args = [
|
||||
"-NoProfile",
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
scriptPath,
|
||||
"-username",
|
||||
process.env.ADMUSER, // needs moved to somewhere else.
|
||||
"-admpass",
|
||||
process.env.ADMPASSWORD, // needs moved to somewhere else.
|
||||
"-devFolder",
|
||||
process.env.DEVFOLDER,
|
||||
"-server",
|
||||
serverInfo[0].serverDNS,
|
||||
"-serverIP",
|
||||
serverInfo[0].idAddress,
|
||||
"-token",
|
||||
serverInfo[0].plantToken,
|
||||
"-build",
|
||||
`${process.env.DEVFOLDER}\\builds`,
|
||||
"-location",
|
||||
serverInfo[0].serverLoc,
|
||||
"-obslst",
|
||||
serverInfo[0].oldVersion,
|
||||
"-obsBuild",
|
||||
app.admConfig.oldBuild,
|
||||
,
|
||||
];
|
||||
const scriptPath = `${process.env.DEVFOLDER}\\server\\scripts\\update.ps1 `;
|
||||
const args = [
|
||||
"-NoProfile",
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
scriptPath,
|
||||
"-username",
|
||||
process.env.ADMUSER, // needs moved to somewhere else.
|
||||
"-admpass",
|
||||
process.env.ADMPASSWORD, // needs moved to somewhere else.
|
||||
"-devFolder",
|
||||
process.env.DEVFOLDER,
|
||||
"-server",
|
||||
serverInfo[0].serverDNS,
|
||||
"-serverIP",
|
||||
serverInfo[0].idAddress,
|
||||
"-token",
|
||||
serverInfo[0].plantToken,
|
||||
"-build",
|
||||
`${process.env.DEVFOLDER}\\builds`,
|
||||
"-location",
|
||||
serverInfo[0].serverLoc,
|
||||
"-obslst",
|
||||
serverInfo[0].oldVersion,
|
||||
"-obsBuild",
|
||||
app.admConfig.oldBuild,
|
||||
,
|
||||
];
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const process = spawn("powershell", args);
|
||||
// change the server to upgradeing
|
||||
await db
|
||||
.update(serverData)
|
||||
.set({isUpgrading: true})
|
||||
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
||||
//let stdout = "";
|
||||
//let stderr = "";
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const process = spawn("powershell", args);
|
||||
// change the server to upgradeing
|
||||
await db
|
||||
.update(serverData)
|
||||
.set({ isUpgrading: true })
|
||||
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
||||
//let stdout = "";
|
||||
//let stderr = "";
|
||||
|
||||
// Collect stdout data
|
||||
process.stdout.on("data", (data) => {
|
||||
const output = data.toString().trim();
|
||||
createLog("info", "lst", "serverUpdater", `${output}`);
|
||||
//onData(output);
|
||||
});
|
||||
|
||||
// Collect stderr data
|
||||
process.stderr.on("data", (data) => {
|
||||
const output = data.toString().trim();
|
||||
createLog("info", "lst", "serverUpdater", `${output}`);
|
||||
//onData(output);
|
||||
});
|
||||
|
||||
// Handle process close
|
||||
process.on("close", async (code) => {
|
||||
if (code === 0) {
|
||||
// if (count >= servers) {
|
||||
// //onClose(`Server completed with code: ${code}`);
|
||||
// }
|
||||
createLog("info", "lst", "serverUpdater", `${server}`);
|
||||
|
||||
//update the last build.
|
||||
try {
|
||||
await db
|
||||
.update(serverData)
|
||||
.set({lastUpdated: sql`NOW()`, isUpgrading: false})
|
||||
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"serverUpdater",
|
||||
`${server?.toLowerCase()}, has been updated and can now be used again.`
|
||||
);
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"serverUpdater",
|
||||
`There was an error updating the last time the server was updated: ${error}`
|
||||
);
|
||||
}
|
||||
|
||||
resolve({
|
||||
success: true,
|
||||
message: `${server?.toLowerCase()}, has been updated and can now be used again.`,
|
||||
});
|
||||
} else {
|
||||
const errorMessage = `Process exited with code ${code}`;
|
||||
|
||||
// if (count >= servers) {
|
||||
// //onClose(code);
|
||||
// }
|
||||
|
||||
reject({
|
||||
success: false,
|
||||
message: `${server?.toLowerCase()}, Has encounted an error while updating.`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Handle errors with the process itself
|
||||
process.on("error", (error) => {
|
||||
//onError(err.message);
|
||||
createLog("error", "lst", "serverUpdater", `${error}`);
|
||||
reject(error);
|
||||
});
|
||||
// Collect stdout data
|
||||
process.stdout.on("data", (data) => {
|
||||
const output = data.toString().trim();
|
||||
createLog("info", "lst", "serverUpdater", `${output}`);
|
||||
//onData(output);
|
||||
});
|
||||
|
||||
// Collect stderr data
|
||||
process.stderr.on("data", (data) => {
|
||||
const output = data.toString().trim();
|
||||
createLog("info", "lst", "serverUpdater", `${output}`);
|
||||
//onData(output);
|
||||
});
|
||||
|
||||
// Handle process close
|
||||
process.on("close", async (code) => {
|
||||
if (code === 0) {
|
||||
// if (count >= servers) {
|
||||
// //onClose(`Server completed with code: ${code}`);
|
||||
// }
|
||||
createLog("info", "lst", "serverUpdater", `${server}`);
|
||||
|
||||
//update the last build.
|
||||
try {
|
||||
await db
|
||||
.update(serverData)
|
||||
.set({ lastUpdated: sql`NOW()`, isUpgrading: false })
|
||||
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"serverUpdater",
|
||||
`${server?.toLowerCase()}, has been updated and can now be used again.`
|
||||
);
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"serverUpdater",
|
||||
`There was an error updating the last time the server was updated: ${error}`
|
||||
);
|
||||
}
|
||||
|
||||
resolve({
|
||||
success: true,
|
||||
message: `${server?.toLowerCase()}, has been updated and can now be used again.`,
|
||||
});
|
||||
} else {
|
||||
const errorMessage = `Process exited with code ${code}`;
|
||||
|
||||
// if (count >= servers) {
|
||||
// //onClose(code);
|
||||
// }
|
||||
|
||||
reject({
|
||||
success: false,
|
||||
message: `${server?.toLowerCase()}, Has encounted an error while updating.`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Handle errors with the process itself
|
||||
process.on("error", (error) => {
|
||||
//onError(err.message);
|
||||
createLog("error", "lst", "serverUpdater", `${error}`);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
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`);
|
||||
let count = 1;
|
||||
for (const server of servers) {
|
||||
try {
|
||||
const updateToServer = await updateServer(devApp, server.plantToken);
|
||||
createLog("info", "lst", "serverUpdater", `${server.sName} was updated.`);
|
||||
count = count + 1;
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"serverUpdater",
|
||||
`Running the update on all servers`
|
||||
);
|
||||
let count = 1;
|
||||
for (const server of servers) {
|
||||
try {
|
||||
const updateToServer = await updateServer(devApp, server.plantToken);
|
||||
createLog("info", "lst", "serverUpdater", `${server.sName} was updated.`);
|
||||
count = count + 1;
|
||||
|
||||
//return {success: true, message: `${server.sName} was updated.`, data: updateToServer};
|
||||
} catch (error: any) {
|
||||
createLog("info", "lst", "serverUpdater", `Error updating ${server.sName}: ${error.message}`);
|
||||
//return {success: false, message: `Error updating ${server.sName}: ${error.message}`};
|
||||
}
|
||||
//return {success: true, message: `${server.sName} was updated.`, data: updateToServer};
|
||||
} catch (error: any) {
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"serverUpdater",
|
||||
`Error updating ${server.sName}: ${error.message}`
|
||||
);
|
||||
//return {success: false, message: `Error updating ${server.sName}: ${error.message}`};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ const updateBuildNumber = (appLock: string) => {
|
||||
// Auto-commit changes
|
||||
execSync("git add package.json");
|
||||
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 {
|
||||
createLog(
|
||||
|
||||
@@ -3,9 +3,14 @@ import axios from "axios";
|
||||
export const ocmeInv = async (data: any) => {
|
||||
try {
|
||||
const res = await axios.post(
|
||||
"http://usday1vms010:3250/api/v1/getLaneData",
|
||||
{lane: data.lane, laneType: data.laneType},
|
||||
{headers: {"Content-Type": "application/json", Connection: "keep-alive"}}
|
||||
"http://usday1vms010:3250/api/v1/getlanedata",
|
||||
{ lane: data.lane, laneType: data.laneType },
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Connection: "keep-alive",
|
||||
},
|
||||
}
|
||||
);
|
||||
// console.log(res.data.data);
|
||||
|
||||
|
||||
@@ -1,25 +1,39 @@
|
||||
import {db} from "../../../../database/dbclient.js";
|
||||
import {ocmeData} from "../../../../database/schema/ocme.js";
|
||||
import {differenceInMinutes} from "date-fns";
|
||||
import {createLog} from "../../logger/logger.js";
|
||||
import {eq} from "drizzle-orm";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { ocmeData } from "../../../../database/schema/ocme.js";
|
||||
import { differenceInMinutes } from "date-fns";
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export const getInfo = async () => {
|
||||
let ocmeInfo: any = [];
|
||||
try {
|
||||
ocmeInfo = await db.select().from(ocmeData).where(eq(ocmeData.pickedUp, false));
|
||||
let ocmeInfo: any = [];
|
||||
try {
|
||||
ocmeInfo = await db
|
||||
.select()
|
||||
.from(ocmeData)
|
||||
.where(eq(ocmeData.pickedUp, false));
|
||||
|
||||
// add in the time difference
|
||||
ocmeInfo = ocmeInfo.map((o: any) => {
|
||||
const now = new Date(Date.now());
|
||||
const diff = differenceInMinutes(now, o.add_Date!);
|
||||
return {...o, waitingFor: diff};
|
||||
});
|
||||
createLog("info", "ocme", "ocme", `There are ${ocmeInfo.length} pallet(s) to be picked up.`);
|
||||
} catch (error) {
|
||||
createLog("error", "ocme", "ocme", "There was an error trying to retrive the ocmeInfo.");
|
||||
throw Error("There was an error trying to retrive the.");
|
||||
}
|
||||
// add in the time difference
|
||||
ocmeInfo = ocmeInfo.map((o: any) => {
|
||||
const now = new Date(Date.now());
|
||||
//const strippedDate = o.add_Date.replace("Z", "");
|
||||
const diff = differenceInMinutes(now, o.add_Date);
|
||||
return { ...o, waitingFor: diff };
|
||||
});
|
||||
createLog(
|
||||
"info",
|
||||
"ocme",
|
||||
"ocme",
|
||||
`There are ${ocmeInfo.length} pallet(s) to be picked up.`
|
||||
);
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"ocme",
|
||||
"ocme",
|
||||
"There was an error trying to retrive the ocmeInfo."
|
||||
);
|
||||
throw Error("There was an error trying to retrive the.");
|
||||
}
|
||||
|
||||
return ocmeInfo;
|
||||
return ocmeInfo;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {OpenAPIHono} from "@hono/zod-openapi";
|
||||
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||
|
||||
// routes
|
||||
import getInfo from "./route/getInfo.js";
|
||||
@@ -7,35 +7,52 @@ import pickedup from "./route/pickedUp.js";
|
||||
import postsscc from "./route/postSSCC.js";
|
||||
import getShipments from "./route/getShipmentPallets.js";
|
||||
import cycleCount from "./route/cycleCount.js";
|
||||
import {serve} from "@hono/node-server";
|
||||
import {createLog} from "../logger/logger.js";
|
||||
import {db} from "../../../database/dbclient.js";
|
||||
import {settings} from "../../../database/schema/settings.js";
|
||||
import { serve } from "@hono/node-server";
|
||||
import { createLog } from "../logger/logger.js";
|
||||
import { db } from "../../../database/dbclient.js";
|
||||
import { settings } from "../../../database/schema/settings.js";
|
||||
import manualTrigger from "./route/triggerCamera.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
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 isActive = setting.filter((n) => n.name === "ocmeService");
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
app.route("/api/v1", route);
|
||||
app.route("/api/v1", route);
|
||||
});
|
||||
|
||||
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") {
|
||||
serve(
|
||||
{
|
||||
fetch: app.fetch,
|
||||
port: Number(port),
|
||||
hostname: "0.0.0.0",
|
||||
},
|
||||
(info) => {
|
||||
createLog("info", "LST", "server", `Ocme section is listening on http://${info.address}:${info.port}`);
|
||||
}
|
||||
);
|
||||
serve(
|
||||
{
|
||||
fetch: app.fetch,
|
||||
port: Number(port),
|
||||
hostname: "0.0.0.0",
|
||||
},
|
||||
(info) => {
|
||||
createLog(
|
||||
"info",
|
||||
"LST",
|
||||
"server",
|
||||
`Ocme section is listening on http://${info.address}:${info.port}`
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default app;
|
||||
|
||||
@@ -1,60 +1,71 @@
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
||||
import {cycleCount} from "../controller/cycleCount.js";
|
||||
import type {User} from "../../../types/users.js";
|
||||
import {verify} from "hono/jwt";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||
import { cycleCount } from "../controller/cycleCount.js";
|
||||
import type { User } from "../../../types/users.js";
|
||||
import { verify } from "hono/jwt";
|
||||
|
||||
const app = new OpenAPIHono({strict: false});
|
||||
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 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 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
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
|
||||
@@ -1,94 +1,114 @@
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {getShipmentPallets} from "../controller/getShipmentPallets.js";
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { getShipmentPallets } from "../controller/getShipmentPallets.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const ShipmentID = z.object({
|
||||
shipmentID: z.string().optional().openapi({example: "14558"}),
|
||||
shipmentID: z.string().optional().openapi({ example: "14558" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Post New running number to be picked up.",
|
||||
method: "post",
|
||||
path: "/getshipmentpallets",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": {schema: ShipmentID},
|
||||
},
|
||||
},
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Post New running number to be picked up.",
|
||||
method: "post",
|
||||
path: "/GetShipmentPallets",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: ShipmentID },
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
success: z.boolean().openapi({example: true}),
|
||||
message: z.string().openapi({example: "Starter"}),
|
||||
// data: z
|
||||
// .array(z.object({sscc: z.string().optional()}))
|
||||
// .optional()
|
||||
// .openapi({example: []}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
400: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
success: z.boolean().openapi({example: false}),
|
||||
message: z.string().optional().openapi({example: "Internal Server error"}),
|
||||
data: z.array(z.object({})).optional().openapi({example: []}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
// 401: {
|
||||
// content: {
|
||||
// "application/json": {
|
||||
// schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
|
||||
// },
|
||||
// },
|
||||
// description: "Unauthorized",
|
||||
// },
|
||||
// 500: {
|
||||
// content: {
|
||||
// "application/json": {
|
||||
// schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
|
||||
// },
|
||||
// },
|
||||
// description: "Internal Server Error",
|
||||
// },
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
success: z.boolean().openapi({ example: true }),
|
||||
message: z.string().openapi({ example: "Starter" }),
|
||||
// data: z
|
||||
// .array(z.object({sscc: z.string().optional()}))
|
||||
// .optional()
|
||||
// .openapi({example: []}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
try {
|
||||
const data = await c.req.json();
|
||||
apiHit(c, {endpoint: "api/ocme/getshipmentpallets", lastBody: data});
|
||||
description: "Response message",
|
||||
},
|
||||
400: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
success: z.boolean().openapi({ example: false }),
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Internal Server error" }),
|
||||
data: z.array(z.object({})).optional().openapi({ example: [] }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
// 401: {
|
||||
// content: {
|
||||
// "application/json": {
|
||||
// schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
|
||||
// },
|
||||
// },
|
||||
// description: "Unauthorized",
|
||||
// },
|
||||
// 500: {
|
||||
// content: {
|
||||
// "application/json": {
|
||||
// schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
|
||||
// },
|
||||
// },
|
||||
// description: "Internal Server Error",
|
||||
// },
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
try {
|
||||
const data = await c.req.json();
|
||||
apiHit(c, { endpoint: "api/ocme/getshipmentpallets", lastBody: data });
|
||||
|
||||
if (!data.shipmentID) {
|
||||
return c.json(
|
||||
{success: false, message: "You are missing the shipment id please try again.", data: []},
|
||||
400
|
||||
);
|
||||
}
|
||||
console.log;
|
||||
|
||||
const shiptmentData = await getShipmentPallets(data.shipmentID);
|
||||
if (!data.shipmentID) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "You are missing the shipment id please try again.",
|
||||
data: [],
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
return c.json(
|
||||
{success: shiptmentData.success, message: shiptmentData.message, data: shiptmentData.data ?? []},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json({success: false, message: "There was an error getting the shipment data.", data: error}, 400);
|
||||
}
|
||||
const shiptmentData = await getShipmentPallets(data.shipmentID);
|
||||
|
||||
return c.json(
|
||||
{
|
||||
success: shiptmentData.success,
|
||||
message: shiptmentData.message,
|
||||
data: shiptmentData.data ?? [],
|
||||
},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error getting the shipment data.",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
|
||||
@@ -3,44 +3,64 @@
|
||||
* Phase 2 we will just reprint the tag that was generated at the line
|
||||
*/
|
||||
|
||||
import {createLog} from "../../../logger/logger.js";
|
||||
import type {TagData} from "../tagData.js";
|
||||
import {tagStuff} from "../tags/crudTag.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import type { TagData } from "../tagData.js";
|
||||
import { tagStuff } from "../tags/crudTag.js";
|
||||
|
||||
export const wrapperStuff = async (tagData: TagData[]) => {
|
||||
if (tagData.length != 1) {
|
||||
createLog(
|
||||
"error",
|
||||
"rfid",
|
||||
"rfid",
|
||||
`There are ${tagData.length} tags and this ${tagData[0].reader} only allows 1 tag to create a label.`
|
||||
);
|
||||
tagStuff(tagData);
|
||||
} else {
|
||||
const tagdata = await tagStuff(tagData);
|
||||
|
||||
/**
|
||||
* 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 (!station3) {
|
||||
createLog(
|
||||
"error",
|
||||
"rfid",
|
||||
"rfid",
|
||||
`${tagdata.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.
|
||||
// more testing will need to be done on this.
|
||||
}
|
||||
|
||||
// check if a running number exists
|
||||
if (station3.runningNumber) {
|
||||
createLog("info", "rfid", "rfid", `Reprint label ${station3.runningNumber}`);
|
||||
} else {
|
||||
createLog("info", "rfid", "rfid", `A new labels will be created and linked to this ${tagdata.tag} tag`);
|
||||
}
|
||||
if (tagData.length != 1) {
|
||||
createLog(
|
||||
"error",
|
||||
"rfid",
|
||||
"rfid",
|
||||
`There are ${tagData.length} tags and this ${tagData[0].reader} only allows 1 tag to create a label.`
|
||||
);
|
||||
tagStuff(tagData);
|
||||
} else {
|
||||
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.
|
||||
*/
|
||||
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) {
|
||||
createLog(
|
||||
"error",
|
||||
"rfid",
|
||||
"rfid",
|
||||
`${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.
|
||||
// more testing will need to be done on this.
|
||||
}
|
||||
|
||||
// check if a running number exists
|
||||
if (station3.runningNumber) {
|
||||
createLog(
|
||||
"info",
|
||||
"rfid",
|
||||
"rfid",
|
||||
`Reprint label ${station3.runningNumber}`
|
||||
);
|
||||
} else {
|
||||
createLog(
|
||||
"info",
|
||||
"rfid",
|
||||
"rfid",
|
||||
`A new labels will be created and linked to this ${tagdata.tag} tag`
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user