Compare commits

...

6 Commits

9 changed files with 172 additions and 87 deletions

9
.gitignore vendored
View File

@@ -5,6 +5,10 @@ dist
apiDocsLSTV2 apiDocsLSTV2
testFiles testFiles
builds builds
nssm.exe
backend-0.1.2-217.zip
backend-0.1.2-218.zip
postgresql-17.2-3-windows-x64.exe
# ---> Node # ---> Node
@@ -143,8 +147,3 @@ dist
.yarn/install-state.gz .yarn/install-state.gz
.pnp.* .pnp.*
nssm.exe
backend-0.1.2-217.zip
postgresql-17.2-3-windows-x64.exe

View File

@@ -7,7 +7,7 @@ export function getServers(token: string) {
queryFn: () => fetchSettings(token), queryFn: () => fetchSettings(token),
enabled: !!token, enabled: !!token,
staleTime: 1000, staleTime: 1000,
refetchInterval: 500, refetchInterval: 2500,
refetchOnWindowFocus: true, refetchOnWindowFocus: true,
}); });
} }

View File

@@ -1,77 +1,77 @@
{ {
"name": "lstv2", "name": "lstv2",
"version": "2.8.0", "version": "2.8.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "concurrently -n \"server,frontend\" -c \"#007755,#2f6da3\" \"npm run dev:server\" \"cd frontend && npm run dev\"", "dev": "concurrently -n \"server,frontend\" -c \"#007755,#2f6da3\" \"npm run dev:server\" \"cd frontend && npm run dev\"",
"dev:server": "dotenvx run -f .env -- tsx watch server/index.ts", "dev:server": "dotenvx run -f .env -- tsx watch server/index.ts",
"dev:frontend": "cd frontend && npm run dev", "dev:frontend": "cd frontend && npm run dev",
"dev:dbgen": " drizzle-kit generate --config=drizzle-dev.config.ts", "dev:dbgen": " drizzle-kit generate --config=drizzle-dev.config.ts",
"dev:dbmigrate": " drizzle-kit migrate --config=drizzle-dev.config.ts", "dev:dbmigrate": " drizzle-kit migrate --config=drizzle-dev.config.ts",
"build": "npm run build:server && npm run build:frontend", "build": "npm run build:server && npm run build:frontend",
"build:server": "rimraf build && tsc --build && xcopy server\\scripts dist\\server\\scripts /E /I /Y && xcopy server\\services\\server\\utils\\serverData.json dist\\server\\services\\server\\utils /E /I /Y ", "build:server": "rimraf build && tsc --build && xcopy server\\scripts dist\\server\\scripts /E /I /Y && xcopy server\\services\\server\\utils\\serverData.json dist\\server\\services\\server\\utils /E /I /Y ",
"build:frontend": "cd frontend && npm run build", "build:frontend": "cd frontend && npm run build",
"start": "set NODE_ENV=production && npm run start:server", "start": "set NODE_ENV=production && npm run start:server",
"start:server": "dotenvx run -f .env -- node dist/server/index.js", "start:server": "dotenvx run -f .env -- node dist/server/index.js",
"db:generate": "npx drizzle-kit generate", "db:generate": "npx drizzle-kit generate",
"db:migrate": "npx drizzle-kit push", "db:migrate": "npx drizzle-kit push",
"db:dev": "npm run build && npm run db:generate && npm run db:migrate", "db:dev": "npm run build && npm run db:generate && npm run db:migrate",
"deploy": "standard-version --conventional-commits && npm run prodBuild", "deploy": "standard-version --conventional-commits && npm run prodBuild",
"zipServer": "dotenvx run -f .env -- tsx server/scripts/zipUpBuild.ts \"C:\\Users\\matthes01\\Documents\\lstv2\"", "zipServer": "dotenvx run -f .env -- tsx server/scripts/zipUpBuild.ts \"C:\\Users\\matthes01\\Documents\\lstv2\"",
"prodBuild": "powershell -ExecutionPolicy Bypass -File server/scripts/build.ps1 -dir \"C:\\Users\\matthes01\\Documents\\lstv2\" && npm run zipServer", "prodBuild": "powershell -ExecutionPolicy Bypass -File server/scripts/build.ps1 -dir \"C:\\Users\\matthes01\\Documents\\lstv2\" && npm run zipServer",
"commit": "cz", "commit": "cz",
"prodinstall": "npm i --omit=dev && npm run db:migrate", "prodinstall": "npm i --omit=dev && npm run db:migrate",
"checkupdates": "npm-check-updates" "checkupdates": "npm-check-updates"
}, },
"dependencies": { "dependencies": {
"@dotenvx/dotenvx": "^1.38.3", "@dotenvx/dotenvx": "^1.38.3",
"@hono/node-server": "^1.13.8", "@hono/node-server": "^1.13.8",
"@hono/zod-openapi": "^0.18.4", "@hono/zod-openapi": "^0.18.4",
"@scalar/hono-api-reference": "^0.5.175", "@scalar/hono-api-reference": "^0.5.175",
"@types/jsonwebtoken": "^9.0.8", "@types/jsonwebtoken": "^9.0.8",
"adm-zip": "^0.5.16", "adm-zip": "^0.5.16",
"axios": "^1.7.9", "axios": "^1.7.9",
"bcrypt": "^5.1.1", "bcrypt": "^5.1.1",
"compression": "^1.8.0", "compression": "^1.8.0",
"cookie": "^1.0.2", "cookie": "^1.0.2",
"date-fns": "^4.1.0", "date-fns": "^4.1.0",
"dotenv": "^16.4.7", "dotenv": "^16.4.7",
"drizzle-kit": "^0.30.4", "drizzle-kit": "^0.30.4",
"drizzle-orm": "^0.39.3", "drizzle-orm": "^0.39.3",
"drizzle-zod": "^0.7.0", "drizzle-zod": "^0.7.0",
"jsonwebtoken": "^9.0.2", "jsonwebtoken": "^9.0.2",
"mssql": "^11.0.1", "mssql": "^11.0.1",
"nodemailer": "^6.10.0", "nodemailer": "^6.10.0",
"nodemailer-express-handlebars": "^7.0.0", "nodemailer-express-handlebars": "^7.0.0",
"pg": "^8.13.3", "pg": "^8.13.3",
"pino": "^9.6.0", "pino": "^9.6.0",
"pino-abstract-transport": "^2.0.0", "pino-abstract-transport": "^2.0.0",
"pino-pretty": "^13.0.0", "pino-pretty": "^13.0.0",
"postgres": "^3.4.5", "postgres": "^3.4.5",
"zod": "^3.24.2" "zod": "^3.24.2"
}, },
"devDependencies": { "devDependencies": {
"@types/adm-zip": "^0.5.7", "@types/adm-zip": "^0.5.7",
"@types/bcrypt": "^5.0.2", "@types/bcrypt": "^5.0.2",
"@types/js-cookie": "^3.0.6", "@types/js-cookie": "^3.0.6",
"@types/mssql": "^9.1.7", "@types/mssql": "^9.1.7",
"@types/node": "^22.13.5", "@types/node": "^22.13.5",
"@types/pg": "^8.11.11", "@types/pg": "^8.11.11",
"concurrently": "^8.2.0", "concurrently": "^8.2.0",
"cz-conventional-changelog": "^3.3.0", "cz-conventional-changelog": "^3.3.0",
"dotenv": "^16.3.1", "dotenv": "^16.3.1",
"rimraf": "^6.0.1", "rimraf": "^6.0.1",
"standard-version": "^9.5.0", "standard-version": "^9.5.0",
"tsx": "^4.7.1", "tsx": "^4.7.1",
"typescript": "~5.7.3" "typescript": "~5.7.3"
}, },
"config": { "config": {
"commitizen": { "commitizen": {
"path": "./node_modules/cz-conventional-changelog" "path": "./node_modules/cz-conventional-changelog"
}
},
"admConfig": {
"build": 20,
"oldBuild": "backend-0.1.2-218.zip"
} }
}, }
"admConfig": {
"build": 20,
"oldBuild": "backend-0.1.2-217.zip"
}
}

View File

@@ -53,7 +53,7 @@ JWT_ACCESS_EXPIRATION="1h"
JWT_REFRESH_EXPIRATION="7d" JWT_REFRESH_EXPIRATION="7d"
# this code will need to be used when a user needs to have access to everything. # this code will need to be used when a user needs to have access to everything.
SECRETOVERRIDECODE="mVSDCpBdxreIJ979ziI71GRubBc2mqVqvZdfA22CB7smBfqlE9S3rKTE909yCHte" SECRETOVERRIDECODE="supersecretKey"
# Database url - please change the password if this is all you changed # Database url - please change the password if this is all you changed
DATABASE_URL="postgresql://postgres:PASSWORD@localhost:5432/lst_db" DATABASE_URL="postgresql://postgres:PASSWORD@localhost:5432/lst_db"

View File

@@ -5,6 +5,7 @@ import {eq, sql} from "drizzle-orm";
import {checkPassword} from "../utils/checkPassword.js"; import {checkPassword} from "../utils/checkPassword.js";
import {roleCheck} from "./userRoles/getUserAccess.js"; import {roleCheck} from "./userRoles/getUserAccess.js";
import {createLog} from "../../logger/logger.js"; import {createLog} from "../../logger/logger.js";
import {differenceInDays} from "date-fns";
/** /**
* Authenticate a user and return a JWT. * Authenticate a user and return a JWT.
@@ -50,7 +51,14 @@ export async function login(
.set({lastLogin: sql`NOW()`}) .set({lastLogin: sql`NOW()`})
.where(eq(users.user_id, user[0].user_id)) .where(eq(users.user_id, user[0].user_id))
.returning({lastLogin: users.lastLogin}); .returning({lastLogin: users.lastLogin});
createLog("info", "lst", "auth", `Its been 5days since ${user[0].username} has logged in`); createLog(
"info",
"lst",
"auth",
`Its been ${differenceInDays(lastLog[0]?.lastLogin ?? "", new Date(Date.now()))} days since ${
user[0].username
} has logged in`
);
//]); //]);
} catch (error) { } catch (error) {
createLog("error", "lst", "auth", "There was an error updating the user last login"); createLog("error", "lst", "auth", "There was an error updating the user last login");

View File

@@ -31,6 +31,9 @@ export const wrapperStuff = async (tagData: TagData[]) => {
"rfid", "rfid",
`${tagdata.tag}, Did not come from a line please check the pallet and manually print the label.` `${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 // check if a running number exists

View File

@@ -0,0 +1,36 @@
import {db} from "../../../../../database/dbclient.js";
import {rfidTags} from "../../../../../database/schema/rfidTags.js";
import {createLog} from "../../../logger/logger.js";
export const manualTag = async (tag: string, area: string) => {
/**
* we only allow tags to be manually added from the wrappers
*/
// create the proper string
const number = tag.toString().padStart(9, "0");
const tagString = `ALPLA${number}`;
const newTag = {
tagHex: Buffer.from(tagString, "utf8").toString("hex").toUpperCase(),
tag: tagString,
lastRead: new Date(Date.now()),
counts: [{area: area, timesHere: 1}], //jsonb("counts").notNull(), //.default([{area: 1, timesHere: 5}]).notNull(),
lastareaIn: area,
antenna: 0,
tagStrength: -1,
};
try {
// insert the tag with the onConflict update the tag
const tag = await db.insert(rfidTags).values(newTag).returning({
tag: rfidTags.tag,
runningNumber: rfidTags.runningNumber,
counts: rfidTags.counts,
lastareaIn: rfidTags.lastareaIn,
});
createLog("info", "rfid", "rfid", `Tags were just added, and label printed.`);
// do the label thing here
return {success: true, message: `${tagString} was just added, and label printed.`, data: tag};
} catch (error) {
createLog("error", "rfid", "rfid", `${JSON.stringify(error)}`);
return {success: false, message: `Error creating a new tag`, data: error};
}
};

View File

@@ -0,0 +1,39 @@
//http://usday1vms006:4000/api/v1/zebra/wrapper1
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import {responses} from "../../../globalUtils/routeDefs/responses.js";
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
import {manualTag} from "../controller/tags/manualTag.js";
const app = new OpenAPIHono();
const RequestBody = z.object({
tagNumber: z.string().openapi({example: "2541"}),
});
app.openapi(
createRoute({
tags: ["rfid"],
summary: "Post a manual Tag",
method: "post",
path: "/manualtag",
middleware: authMiddleware,
request: {
body: {content: {"application/json": {schema: RequestBody}}},
},
responses: responses(),
}),
async (c) => {
const body =
(await c.req.json()) ??
c.json({success: false, message: `Please check that you are sending over a json object`}, 400);
try {
const tag = await manualTag(body.tag, body.area);
return c.json({success: tag.success, message: tag.message, data: tag.data}, 200);
} catch (error) {
return c.json({success: true, message: `There was an error with entering a new tag`, error}, 400);
}
}
);
export default app;

View File

@@ -53,7 +53,7 @@
"contactPhone": "6366970253", "contactPhone": "6366970253",
"customerTiAcc": "ALPL01HOUSINT", "customerTiAcc": "ALPL01HOUSINT",
"lstServerPort": "4000", "lstServerPort": "4000",
"active": false, "active": true,
"serverLoc": "E:\\LST\\lstv2", "serverLoc": "E:\\LST\\lstv2",
"oldVersion": "C:\\Users\\adm_matthes01\\Desktop\\lst_backend", "oldVersion": "C:\\Users\\adm_matthes01\\Desktop\\lst_backend",
"shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]",
@@ -293,7 +293,7 @@
"contactPhone": "6366970253", "contactPhone": "6366970253",
"customerTiAcc": "ALPL01SHERMANINT", "customerTiAcc": "ALPL01SHERMANINT",
"lstServerPort": "4000", "lstServerPort": "4000",
"active": false, "active": true,
"serverLoc": "E:\\LST\\lstv2", "serverLoc": "E:\\LST\\lstv2",
"oldVersion": "C:\\Users\\adm_matthes01\\Desktop\\lst_backend", "oldVersion": "C:\\Users\\adm_matthes01\\Desktop\\lst_backend",
"shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]",
@@ -309,8 +309,8 @@
"streetAddress": "825 Rail Way", "streetAddress": "825 Rail Way",
"cityState": "West Bend, WI", "cityState": "West Bend, WI",
"zipcode": "53095", "zipcode": "53095",
"contactEmail": "blake.matthes@alpla.com", "contactEmail": "shippingreceivingwestbend@groups.alpla.com",
"contactPhone": "6366970253", "contactPhone": "262-808-4211",
"customerTiAcc": "ALPL01WBINT", "customerTiAcc": "ALPL01WBINT",
"lstServerPort": "4000", "lstServerPort": "4000",
"active": true, "active": true,