This commit is contained in:
2025-03-25 07:57:55 -05:00
5 changed files with 421 additions and 254 deletions

View File

@@ -41,22 +41,19 @@ export default function OcmeCycleCount() {
setCounting(true);
toast.success(`Cycle count started`);
try {
const res = await axios.post("/ocme/api/v1/cycleCount", data, {
const res = await axios.post("/ocme/api/v1/cyclecount", data, {
headers: { Authorization: `Bearer ${token}` },
});
console.log(data);
toast.success(res.data.message);
setData(res.data.data);
setCounting(false);
reset();
} catch (error) {
console.log(error);
toast.error("There was an error cycle counting");
setCounting(false);
reset();
}
};
return (
<div className="flex flex-row w-screen">
<div className="m-2 w-5/6">
@@ -70,13 +67,16 @@ export default function OcmeCycleCount() {
<div className="m-2 flex flex-row">
<Input
placeholder="enter lane: L064"
className={errors.lane ? "border-red-500" : ""}
className={
errors.lane ? "border-red-500" : ""
}
aria-invalid={!!errors.lane}
{...register("lane", {
required: true,
minLength: {
value: 3,
message: "The lane is too short!",
message:
"The lane is too short!",
},
})}
/>
@@ -90,20 +90,30 @@ export default function OcmeCycleCount() {
fieldState: {},
//formState,
}) => (
<Select onValueChange={onChange}>
<Select
onValueChange={onChange}
>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Select name or id" />
</SelectTrigger>
<SelectContent>
<SelectItem value="name">Name</SelectItem>
<SelectItem value="laneID">Lane ID</SelectItem>
<SelectItem value="name">
Name
</SelectItem>
<SelectItem value="laneId">
Lane ID
</SelectItem>
</SelectContent>
</Select>
)}
/>
</div>
</div>
<Button className="m-2" type="submit" disabled={counting}>
<Button
className="m-2"
type="submit"
disabled={counting}
>
{counting ? (
<span>Counting...</span>
) : (
@@ -127,7 +137,7 @@ export default function OcmeCycleCount() {
<TableHead>Result</TableHead>
</TableRow>
</TableHeader>
{data?.length === 0 ? (
{data.length === 0 ? (
<TableBody>
{Array(10)
.fill(0)
@@ -162,9 +172,11 @@ export default function OcmeCycleCount() {
</TableBody>
) : (
<>
{data?.map((i: any) => {
{data.map((i: any) => {
let classname = ``;
if (i.info === "Quality Check Required") {
if (
i.info === "Quality Check Required"
) {
classname = `bg-red-500`;
}
if (i.info === "Sent to Inv") {
@@ -172,28 +184,44 @@ export default function OcmeCycleCount() {
}
return (
<TableRow key={i.runningNumber}>
<TableCell className={`font-medium ${classname}`}>
<TableCell
className={`font-medium ${classname}`}
>
{i.alpla_laneID}
</TableCell>
<TableCell className={`font-medium ${classname}`}>
<TableCell
className={`font-medium ${classname}`}
>
{i.alpla_laneDescription}
</TableCell>
<TableCell className={`font-medium ${classname}`}>
<TableCell
className={`font-medium ${classname}`}
>
{i.Article}
</TableCell>
<TableCell className={`font-medium ${classname}`}>
<TableCell
className={`font-medium ${classname}`}
>
{i.alpla_laneDescription}
</TableCell>
<TableCell className={`font-medium ${classname}`}>
<TableCell
className={`font-medium ${classname}`}
>
{i.runningNumber}
</TableCell>
<TableCell className={`font-medium ${classname}`}>
<TableCell
className={`font-medium ${classname}`}
>
{i.ocme}
</TableCell>
<TableCell className={`font-medium ${classname}`}>
<TableCell
className={`font-medium ${classname}`}
>
{i.stock}
</TableCell>
<TableCell className={`font-medium ${classname}`}>
<TableCell
className={`font-medium ${classname}`}
>
{i.info}
</TableCell>
</TableRow>

View File

@@ -21,7 +21,7 @@
"deploy": "standard-version --conventional-commits && npm run prodBuild",
"zipServer": "dotenvx run -f .env -- tsx server/scripts/zipUpBuild.ts \"C:\\Users\\matthes01\\Documents\\lstv2\"",
"v1Build": "cd C:\\Users\\matthes01\\Documents\\logisticsSupportTool && npm run oldBuilder",
"prodBuild": "npm run v1Build && powershell -ExecutionPolicy Bypass -File server/scripts/build.ps1 -dir \"C:\\Users\\matthes01\\Documents\\lstv2\" && npm run zipServer",
"prodBuild": "npm run v1Build && powershell -ExecutionPolicy Bypass -File server/scripts/build.ps1 -dir \"C:\\Users\\matthes01\\Documents\\lstv2-dev\" && npm run zipServer",
"commit": "cz",
"prodinstall": "npm i --omit=dev && npm run db:migrate",
"checkupdates": "npx npm-check-updates"

View File

@@ -4,12 +4,26 @@ 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
@@ -33,7 +47,32 @@ export const updateServer = async (
"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",
@@ -77,6 +116,15 @@ export const updateServer = async (
,
];
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
@@ -87,6 +135,12 @@ export const updateServer = async (
//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 stdout data
process.stdout.on("data", (data) => {
const output = data.toString().trim();
@@ -94,6 +148,12 @@ export const updateServer = async (
//onData(output);
});
// Collect stderr data
process.stderr.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();
@@ -101,6 +161,13 @@ export const updateServer = async (
//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}`);
// Handle process close
process.on("close", async (code) => {
if (code === 0) {
@@ -109,6 +176,26 @@ export const updateServer = async (
// }
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}`
);
}
//update the last build.
try {
await db
@@ -130,6 +217,12 @@ export const updateServer = async (
);
}
resolve({
success: true,
message: `${server?.toLowerCase()}, has been updated and can now be used again.`,
});
} else {
const errorMessage = `Process exited with code ${code}`;
resolve({
success: true,
message: `${server?.toLowerCase()}, has been updated and can now be used again.`,
@@ -137,6 +230,9 @@ export const updateServer = async (
} else {
const errorMessage = `Process exited with code ${code}`;
// if (count >= servers) {
// //onClose(code);
// }
// if (count >= servers) {
// //onClose(code);
// }
@@ -147,6 +243,12 @@ export const updateServer = async (
});
}
});
reject({
success: false,
message: `${server?.toLowerCase()}, Has encounted an error while updating.`,
});
}
});
// Handle errors with the process itself
process.on("error", (error) => {
@@ -155,11 +257,31 @@ export const updateServer = async (
reject(error);
});
});
// 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",
@@ -184,4 +306,15 @@ export async function processAllServers(devApp: string) {
//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}`};
}
}
}

View File

@@ -4,6 +4,12 @@ import { createSSCC } from "../../../globalUtils/createSSCC.js";
import { createLog } from "../../logger/logger.js";
import { query } from "../../sqlServer/prodSqlServer.js";
import { labelData } from "../../sqlServer/querys/materialHelpers/labelInfo.js";
import { db } from "../../../../database/dbclient.js";
import { ocmeData } from "../../../../database/schema/ocme.js";
import { createSSCC } from "../../../globalUtils/createSSCC.js";
import { createLog } from "../../logger/logger.js";
import { query } from "../../sqlServer/prodSqlServer.js";
import { labelData } from "../../sqlServer/querys/materialHelpers/labelInfo.js";
export const postLabelData = async (data: any) => {
console.log(data);