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 { spawn } from "child_process";
|
||||||
import {getAppInfo} from "../globalUtils/appInfo.js";
|
import { getAppInfo } from "../globalUtils/appInfo.js";
|
||||||
import {db} from "../../database/dbclient.js";
|
import { db } from "../../database/dbclient.js";
|
||||||
import {serverData} from "../../database/schema/serverData.js";
|
import { serverData } from "../../database/schema/serverData.js";
|
||||||
import {eq, sql} from "drizzle-orm";
|
import { eq, sql } from "drizzle-orm";
|
||||||
import {createLog} from "../services/logger/logger.js";
|
import { createLog } from "../services/logger/logger.js";
|
||||||
|
|
||||||
type UpdateServerResponse = {
|
type UpdateServerResponse = {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateServer = async (devApp: string, server: string | null): Promise<UpdateServerResponse> => {
|
export const updateServer = async (
|
||||||
const app = await getAppInfo(devApp);
|
devApp: string,
|
||||||
const serverInfo = await db
|
server: string | null
|
||||||
|
): Promise<UpdateServerResponse> => {
|
||||||
|
const app = await getAppInfo(devApp);
|
||||||
|
const serverInfo = await db
|
||||||
.select()
|
.select()
|
||||||
.from(serverData)
|
.from(serverData)
|
||||||
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
||||||
|
|
||||||
if (serverInfo.length === 0) {
|
if (serverInfo.length === 0) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"lst",
|
"lst",
|
||||||
"serverUpdater",
|
"serverUpdater",
|
||||||
`Looks like you are missing the plant token or have entered an incorrect one please try again.`
|
`Looks like you are missing the plant token or have entered an incorrect one please try again.`
|
||||||
);
|
);
|
||||||
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.",
|
||||||
}
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (serverInfo[0].isUpgrading) {
|
if (serverInfo[0].isUpgrading) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"lst",
|
"lst",
|
||||||
"serverUpdater",
|
"serverUpdater",
|
||||||
`Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`
|
`Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: `Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`,
|
message: `Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const scriptPath = `${process.env.DEVFOLDER}\\server\\scripts\\update.ps1 `;
|
const scriptPath = `${process.env.DEVFOLDER}\\server\\scripts\\update.ps1 `;
|
||||||
const args = [
|
const args = [
|
||||||
"-NoProfile",
|
"-NoProfile",
|
||||||
"-ExecutionPolicy",
|
"-ExecutionPolicy",
|
||||||
"Bypass",
|
"Bypass",
|
||||||
"-File",
|
"-File",
|
||||||
scriptPath,
|
scriptPath,
|
||||||
"-username",
|
"-username",
|
||||||
process.env.ADMUSER, // needs moved to somewhere else.
|
process.env.ADMUSER, // needs moved to somewhere else.
|
||||||
"-admpass",
|
"-admpass",
|
||||||
process.env.ADMPASSWORD, // needs moved to somewhere else.
|
process.env.ADMPASSWORD, // needs moved to somewhere else.
|
||||||
"-devFolder",
|
"-devFolder",
|
||||||
process.env.DEVFOLDER,
|
process.env.DEVFOLDER,
|
||||||
"-server",
|
"-server",
|
||||||
serverInfo[0].serverDNS,
|
serverInfo[0].serverDNS,
|
||||||
"-serverIP",
|
"-serverIP",
|
||||||
serverInfo[0].idAddress,
|
serverInfo[0].idAddress,
|
||||||
"-token",
|
"-token",
|
||||||
serverInfo[0].plantToken,
|
serverInfo[0].plantToken,
|
||||||
"-build",
|
"-build",
|
||||||
`${process.env.DEVFOLDER}\\builds`,
|
`${process.env.DEVFOLDER}\\builds`,
|
||||||
"-location",
|
"-location",
|
||||||
serverInfo[0].serverLoc,
|
serverInfo[0].serverLoc,
|
||||||
"-obslst",
|
"-obslst",
|
||||||
serverInfo[0].oldVersion,
|
serverInfo[0].oldVersion,
|
||||||
"-obsBuild",
|
"-obsBuild",
|
||||||
app.admConfig.oldBuild,
|
app.admConfig.oldBuild,
|
||||||
,
|
,
|
||||||
];
|
];
|
||||||
|
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const process = spawn("powershell", args);
|
const process = spawn("powershell", args);
|
||||||
// change the server to upgradeing
|
// change the server to upgradeing
|
||||||
await db
|
await db
|
||||||
.update(serverData)
|
.update(serverData)
|
||||||
.set({isUpgrading: true})
|
.set({ isUpgrading: true })
|
||||||
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
||||||
//let stdout = "";
|
//let stdout = "";
|
||||||
//let stderr = "";
|
//let stderr = "";
|
||||||
|
|
||||||
// Collect stdout data
|
// Collect stdout data
|
||||||
process.stdout.on("data", (data) => {
|
process.stdout.on("data", (data) => {
|
||||||
const output = data.toString().trim();
|
const output = data.toString().trim();
|
||||||
createLog("info", "lst", "serverUpdater", `${output}`);
|
createLog("info", "lst", "serverUpdater", `${output}`);
|
||||||
//onData(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 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) {
|
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(
|
||||||
let count = 1;
|
"info",
|
||||||
for (const server of servers) {
|
"lst",
|
||||||
try {
|
"serverUpdater",
|
||||||
const updateToServer = await updateServer(devApp, server.plantToken);
|
`Running the update on all servers`
|
||||||
createLog("info", "lst", "serverUpdater", `${server.sName} was updated.`);
|
);
|
||||||
count = count + 1;
|
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};
|
//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(
|
||||||
//return {success: false, message: `Error updating ${server.sName}: ${error.message}`};
|
"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
|
// 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(
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,39 @@
|
|||||||
import {db} from "../../../../database/dbclient.js";
|
import { db } from "../../../../database/dbclient.js";
|
||||||
import {ocmeData} from "../../../../database/schema/ocme.js";
|
import { ocmeData } from "../../../../database/schema/ocme.js";
|
||||||
import {differenceInMinutes} from "date-fns";
|
import { differenceInMinutes } from "date-fns";
|
||||||
import {createLog} from "../../logger/logger.js";
|
import { createLog } from "../../logger/logger.js";
|
||||||
import {eq} from "drizzle-orm";
|
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", "");
|
||||||
return {...o, waitingFor: diff};
|
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(
|
||||||
createLog("error", "ocme", "ocme", "There was an error trying to retrive the ocmeInfo.");
|
"info",
|
||||||
throw Error("There was an error trying to retrive the.");
|
"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
|
// routes
|
||||||
import getInfo from "./route/getInfo.js";
|
import getInfo from "./route/getInfo.js";
|
||||||
@@ -7,35 +7,52 @@ import pickedup from "./route/pickedUp.js";
|
|||||||
import postsscc from "./route/postSSCC.js";
|
import postsscc from "./route/postSSCC.js";
|
||||||
import getShipments from "./route/getShipmentPallets.js";
|
import getShipments from "./route/getShipmentPallets.js";
|
||||||
import cycleCount from "./route/cycleCount.js";
|
import cycleCount from "./route/cycleCount.js";
|
||||||
import {serve} from "@hono/node-server";
|
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");
|
||||||
const appRoutes = routes.forEach((route) => {
|
const appRoutes = routes.forEach((route) => {
|
||||||
app.route("/api/v1", route);
|
app.route("/api/v1", 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(
|
||||||
{
|
{
|
||||||
fetch: app.fetch,
|
fetch: app.fetch,
|
||||||
port: Number(port),
|
port: Number(port),
|
||||||
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}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default app;
|
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 { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||||
import {cycleCount} from "../controller/cycleCount.js";
|
import { cycleCount } from "../controller/cycleCount.js";
|
||||||
import type {User} from "../../../types/users.js";
|
import type { User } from "../../../types/users.js";
|
||||||
import {verify} from "hono/jwt";
|
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(),
|
},
|
||||||
}),
|
},
|
||||||
async (c) => {
|
responses: responses(),
|
||||||
apiHit(c, {endpoint: "api/auth/register"});
|
}),
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
async (c) => {
|
||||||
const body = await c.req.json();
|
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] || "";
|
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;
|
||||||
|
|||||||
@@ -1,94 +1,114 @@
|
|||||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
import {getShipmentPallets} from "../controller/getShipmentPallets.js";
|
import { getShipmentPallets } from "../controller/getShipmentPallets.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
const ShipmentID = z.object({
|
const ShipmentID = z.object({
|
||||||
shipmentID: z.string().optional().openapi({example: "14558"}),
|
shipmentID: z.string().optional().openapi({ example: "14558" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
app.openapi(
|
app.openapi(
|
||||||
createRoute({
|
createRoute({
|
||||||
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: {
|
||||||
"application/json": {schema: ShipmentID},
|
"application/json": { schema: ShipmentID },
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
responses: {
|
},
|
||||||
200: {
|
},
|
||||||
content: {
|
responses: {
|
||||||
"application/json": {
|
200: {
|
||||||
schema: z.object({
|
content: {
|
||||||
success: z.boolean().openapi({example: true}),
|
"application/json": {
|
||||||
message: z.string().openapi({example: "Starter"}),
|
schema: z.object({
|
||||||
// data: z
|
success: z.boolean().openapi({ example: true }),
|
||||||
// .array(z.object({sscc: z.string().optional()}))
|
message: z.string().openapi({ example: "Starter" }),
|
||||||
// .optional()
|
// data: z
|
||||||
// .openapi({example: []}),
|
// .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",
|
|
||||||
// },
|
|
||||||
},
|
},
|
||||||
}),
|
description: "Response message",
|
||||||
async (c) => {
|
},
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
400: {
|
||||||
try {
|
content: {
|
||||||
const data = await c.req.json();
|
"application/json": {
|
||||||
apiHit(c, {endpoint: "api/ocme/getshipmentpallets", lastBody: data});
|
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) {
|
console.log;
|
||||||
return c.json(
|
|
||||||
{success: false, message: "You are missing the shipment id please try again.", data: []},
|
|
||||||
400
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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(
|
const shiptmentData = await getShipmentPallets(data.shipmentID);
|
||||||
{success: shiptmentData.success, message: shiptmentData.message, data: shiptmentData.data ?? []},
|
|
||||||
200
|
return c.json(
|
||||||
);
|
{
|
||||||
} catch (error) {
|
success: shiptmentData.success,
|
||||||
return c.json({success: false, message: "There was an error getting the shipment data.", data: error}, 400);
|
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;
|
export default app;
|
||||||
|
|||||||
@@ -3,44 +3,64 @@
|
|||||||
* Phase 2 we will just reprint the tag that was generated at the line
|
* Phase 2 we will just reprint the tag that was generated at the line
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {createLog} from "../../../logger/logger.js";
|
import { createLog } from "../../../logger/logger.js";
|
||||||
import type {TagData} from "../tagData.js";
|
import type { TagData } from "../tagData.js";
|
||||||
import {tagStuff} from "../tags/crudTag.js";
|
import { tagStuff } from "../tags/crudTag.js";
|
||||||
|
|
||||||
export const wrapperStuff = async (tagData: TagData[]) => {
|
export const wrapperStuff = async (tagData: TagData[]) => {
|
||||||
if (tagData.length != 1) {
|
if (tagData.length != 1) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"rfid",
|
"rfid",
|
||||||
"rfid",
|
"rfid",
|
||||||
`There are ${tagData.length} tags and this ${tagData[0].reader} only allows 1 tag to create a label.`
|
`There are ${tagData.length} tags and this ${tagData[0].reader} only allows 1 tag to create a label.`
|
||||||
);
|
);
|
||||||
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.
|
|
||||||
*/
|
|
||||||
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`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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