Compare commits

..

4 Commits

47 changed files with 4922 additions and 2331 deletions

View File

@@ -5,7 +5,7 @@ meta {
} }
post { post {
url: http://localhost:4000/api/auth/login url: http://localhost:4400/api/auth/login
body: json body: json
auth: none auth: none
} }

View File

@@ -5,15 +5,15 @@ meta {
} }
post { post {
url: http://localhost:3000/api/auth/register url: http://localhost:4400/api/auth/register
body: json body: json
auth: none auth: none
} }
body:json { body:json {
{ {
"username": "adm_matthes01", "username": "matthes01",
"email":"blake@alpla.com", "email":"blake.matthes@alpla.com",
"password": "nova0511!" "password": "password"
} }
} }

View File

@@ -0,0 +1,15 @@
meta {
name: getUserroles
type: http
seq: 5
}
get {
url: http://localhost:4400/api/auth/getuseraccess
body: json
auth: bearer
}
auth:bearer {
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVzZXJfaWQiOiIyYzYzODQ3Zi1mMWVjLTRkNTAtOGFkMi05ODBkMWYzZTgwZWIiLCJ1c2VybmFtZSI6Im1hdHRoZXMwMSIsImVtYWlsIjoiYmxha2UubWF0dGhlc0BhbHBsYS5jb20iLCJyb2xlcyI6W10sInJvbGUiOiJ1c2VyIn0sImlhdCI6MTc0MDY3NTMyMiwiZXhwIjoxNzQwNjc4OTIyfQ.D4rLIBAZfo0larMGUmXF6Z2KVnZvRLvth2116JyK2z8
}

View File

@@ -1,6 +1,6 @@
import {text, pgTable, numeric, index, timestamp, boolean, uuid, uniqueIndex} from "drizzle-orm/pg-core"; import {text, pgTable, timestamp, boolean, uuid, uniqueIndex} from "drizzle-orm/pg-core";
import {createInsertSchema, createSelectSchema} from "drizzle-zod"; import {createSelectSchema} from "drizzle-zod";
import {z} from "zod"; //import {z} from "zod";
export const modules = pgTable( export const modules = pgTable(
"modules", "modules",
@@ -26,3 +26,5 @@ export const modules = pgTable(
// }); // });
// Schema for selecting a Expenses - can be used to validate API responses // Schema for selecting a Expenses - can be used to validate API responses
export const selectModuleSchema = createSelectSchema(modules); export const selectModuleSchema = createSelectSchema(modules);
export type Modules = typeof modules;

View File

@@ -1,9 +1,9 @@
import {text, pgTable, numeric, index, timestamp, boolean, uuid, uniqueIndex} from "drizzle-orm/pg-core"; import {text, pgTable, numeric, index, timestamp, boolean, uuid, uniqueIndex} from "drizzle-orm/pg-core";
import {createInsertSchema, createSelectSchema} from "drizzle-zod"; import {createInsertSchema, createSelectSchema} from "drizzle-zod";
import {z} from "zod"; import {z} from "zod";
import {users} from "./users"; import {users} from "./users.js";
import {roles} from "./roles"; import {roles} from "./roles.js";
import {modules} from "./modules"; import {modules} from "./modules.js";
/* /*
we will add the user we will add the user

12
drizzle.config.js Normal file
View File

@@ -0,0 +1,12 @@
import { defineConfig } from "drizzle-kit";
import dotenv from "dotenv";
dotenv.config();
const database = process.env.DATABASE_URL || "";
export default defineConfig({
dialect: "postgresql",
schema: "database/schema",
out: "database/migrations",
dbCredentials: {
url: database,
},
});

View File

@@ -23,7 +23,9 @@
"@tanstack/react-router": "^1.111.11", "@tanstack/react-router": "^1.111.11",
"class-variance-authority": "^0.7.1", "class-variance-authority": "^0.7.1",
"clsx": "^2.1.1", "clsx": "^2.1.1",
"hono": "^4.7.2",
"js-cookie": "^3.0.5", "js-cookie": "^3.0.5",
"jsonwebtoken": "^9.0.2",
"lucide-react": "^0.476.0", "lucide-react": "^0.476.0",
"next-themes": "^0.4.4", "next-themes": "^0.4.4",
"react": "^19.0.0", "react": "^19.0.0",
@@ -43,6 +45,7 @@
"@tanstack/router-plugin": "^1.106.0", "@tanstack/router-plugin": "^1.106.0",
"@types/react": "^19.0.10", "@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4", "@types/react-dom": "^19.0.4",
"@types/react-grid-layout": "^1.3.5",
"@vitejs/plugin-react-swc": "^3.8.0", "@vitejs/plugin-react-swc": "^3.8.0",
"eslint": "^9.21.0", "eslint": "^9.21.0",
"eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-hooks": "^5.0.0",
@@ -2909,6 +2912,16 @@
"@types/react": "^19.0.0" "@types/react": "^19.0.0"
} }
}, },
"node_modules/@types/react-grid-layout": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/@types/react-grid-layout/-/react-grid-layout-1.3.5.tgz",
"integrity": "sha512-WH/po1gcEcoR6y857yAnPGug+ZhkF4PaTUxgAbwfeSH/QOgVSakKHBXoPGad/sEznmkiaK3pqHk+etdWisoeBQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/react": "*"
}
},
"node_modules/@typescript-eslint/eslint-plugin": { "node_modules/@typescript-eslint/eslint-plugin": {
"version": "8.25.0", "version": "8.25.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.25.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.25.0.tgz",
@@ -3317,6 +3330,12 @@
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
} }
}, },
"node_modules/buffer-equal-constant-time": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
"integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==",
"license": "BSD-3-Clause"
},
"node_modules/callsites": { "node_modules/callsites": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
@@ -3533,6 +3552,15 @@
"node": ">=0.3.1" "node": ">=0.3.1"
} }
}, },
"node_modules/ecdsa-sig-formatter": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
"integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
"license": "Apache-2.0",
"dependencies": {
"safe-buffer": "^5.0.1"
}
},
"node_modules/electron-to-chromium": { "node_modules/electron-to-chromium": {
"version": "1.5.107", "version": "1.5.107",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.107.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.107.tgz",
@@ -4029,6 +4057,15 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/hono": {
"version": "4.7.2",
"resolved": "https://registry.npmjs.org/hono/-/hono-4.7.2.tgz",
"integrity": "sha512-8V5XxoOF6SI12jkHkzX/6aLBMU5GEF5g387EjVSQipS0DlxWgWGSMeEayY3CRBjtTUQYwLHx9JYouWqKzy2Vng==",
"license": "MIT",
"engines": {
"node": ">=16.9.0"
}
},
"node_modules/ignore": { "node_modules/ignore": {
"version": "5.3.2", "version": "5.3.2",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
@@ -4202,6 +4239,49 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/jsonwebtoken": {
"version": "9.0.2",
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz",
"integrity": "sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==",
"license": "MIT",
"dependencies": {
"jws": "^3.2.2",
"lodash.includes": "^4.3.0",
"lodash.isboolean": "^3.0.3",
"lodash.isinteger": "^4.0.4",
"lodash.isnumber": "^3.0.3",
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1",
"lodash.once": "^4.0.0",
"ms": "^2.1.1",
"semver": "^7.5.4"
},
"engines": {
"node": ">=12",
"npm": ">=6"
}
},
"node_modules/jwa": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz",
"integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==",
"license": "MIT",
"dependencies": {
"buffer-equal-constant-time": "1.0.1",
"ecdsa-sig-formatter": "1.0.11",
"safe-buffer": "^5.0.1"
}
},
"node_modules/jws": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz",
"integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==",
"license": "MIT",
"dependencies": {
"jwa": "^1.4.1",
"safe-buffer": "^5.0.1"
}
},
"node_modules/keyv": { "node_modules/keyv": {
"version": "4.5.4", "version": "4.5.4",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
@@ -4470,6 +4550,42 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/lodash.includes": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
"integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==",
"license": "MIT"
},
"node_modules/lodash.isboolean": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz",
"integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==",
"license": "MIT"
},
"node_modules/lodash.isinteger": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
"integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==",
"license": "MIT"
},
"node_modules/lodash.isnumber": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz",
"integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==",
"license": "MIT"
},
"node_modules/lodash.isplainobject": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
"integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==",
"license": "MIT"
},
"node_modules/lodash.isstring": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz",
"integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==",
"license": "MIT"
},
"node_modules/lodash.merge": { "node_modules/lodash.merge": {
"version": "4.6.2", "version": "4.6.2",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
@@ -4477,6 +4593,12 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/lodash.once": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
"integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==",
"license": "MIT"
},
"node_modules/loose-envify": { "node_modules/loose-envify": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
@@ -4549,7 +4671,6 @@
"version": "2.1.3", "version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/nanoid": { "node_modules/nanoid": {
@@ -5089,6 +5210,26 @@
"queue-microtask": "^1.2.2" "queue-microtask": "^1.2.2"
} }
}, },
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/scheduler": { "node_modules/scheduler": {
"version": "0.25.0", "version": "0.25.0",
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.25.0.tgz", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.25.0.tgz",
@@ -5099,7 +5240,6 @@
"version": "7.7.1", "version": "7.7.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
"integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==",
"dev": true,
"license": "ISC", "license": "ISC",
"bin": { "bin": {
"semver": "bin/semver.js" "semver": "bin/semver.js"

View File

@@ -5,7 +5,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc -b && vite build", "build": "rimraf dist && tsc -b && vite build",
"lint": "eslint .", "lint": "eslint .",
"preview": "vite preview", "preview": "vite preview",
"shad": "npx shadcn@canary add " "shad": "npx shadcn@canary add "
@@ -26,7 +26,9 @@
"@tanstack/react-router": "^1.111.11", "@tanstack/react-router": "^1.111.11",
"class-variance-authority": "^0.7.1", "class-variance-authority": "^0.7.1",
"clsx": "^2.1.1", "clsx": "^2.1.1",
"hono": "^4.7.2",
"js-cookie": "^3.0.5", "js-cookie": "^3.0.5",
"jsonwebtoken": "^9.0.2",
"lucide-react": "^0.476.0", "lucide-react": "^0.476.0",
"next-themes": "^0.4.4", "next-themes": "^0.4.4",
"react": "^19.0.0", "react": "^19.0.0",
@@ -46,6 +48,7 @@
"@tanstack/router-plugin": "^1.106.0", "@tanstack/router-plugin": "^1.106.0",
"@types/react": "^19.0.10", "@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4", "@types/react-dom": "^19.0.4",
"@types/react-grid-layout": "^1.3.5",
"@vitejs/plugin-react-swc": "^3.8.0", "@vitejs/plugin-react-swc": "^3.8.0",
"eslint": "^9.21.0", "eslint": "^9.21.0",
"eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-hooks": "^5.0.0",

View File

@@ -9,19 +9,23 @@ import {AdminSideBar} from "./side-components/admin";
import {useSessionStore} from "../../lib/store/sessionStore"; import {useSessionStore} from "../../lib/store/sessionStore";
import {hasAccess} from "../../utils/userAccess"; import {hasAccess} from "../../utils/userAccess";
import {moduleActive} from "../../utils/moduleActive"; import {moduleActive} from "../../utils/moduleActive";
import {useModuleStore} from "../../lib/store/useModuleStore";
export function AppSidebar() { export function AppSidebar() {
const {user} = useSessionStore(); const {user} = useSessionStore();
const {modules} = useModuleStore();
console.log(user);
return ( return (
<Sidebar collapsible="icon"> <Sidebar collapsible="icon">
<SidebarContent> <SidebarContent>
<Header /> <Header />
{moduleActive("production") && <ProductionSideBar />} {moduleActive("production") && <ProductionSideBar />}
{moduleActive("logistics") && hasAccess(user, "logistics", "view") && <LogisticsSideBar />} {moduleActive("logistics") && hasAccess(user, "logistics", modules) && <LogisticsSideBar />}
{moduleActive("forklift") && hasAccess(user, "forklift", "view") && <ForkliftSideBar />} {moduleActive("forklift") && hasAccess(user, "forklift", modules) && <ForkliftSideBar />}
{moduleActive("admin") && hasAccess(user, "eom", "view") && <EomSideBar />} {moduleActive("admin") && hasAccess(user, "eom", modules) && <EomSideBar />}
{moduleActive("quality") && hasAccess(user, "quality", "view") && <QualitySideBar />} {moduleActive("quality") && hasAccess(user, "quality", modules) && <QualitySideBar />}
{moduleActive("admin") && hasAccess(user, "admin", "view") && <AdminSideBar />} {moduleActive("admin") && hasAccess(user, "admin", modules) && <AdminSideBar />}
</SidebarContent> </SidebarContent>
<SidebarFooter> <SidebarFooter>
<SidebarTrigger /> <SidebarTrigger />

View File

@@ -13,21 +13,25 @@ const items = [
title: "Silo Adjustments", title: "Silo Adjustments",
url: "#", url: "#",
icon: Cylinder, icon: Cylinder,
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
}, },
{ {
title: "Bulk orders", title: "Bulk orders",
url: "#", url: "#",
icon: Truck, icon: Truck,
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
}, },
{ {
title: "Forecast", title: "Forecast",
url: "#", url: "#",
icon: Truck, icon: Truck,
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
}, },
{ {
title: "Ocme cycle counts", title: "Ocme cycle counts",
url: "#", url: "#",
icon: Package, icon: Package,
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
}, },
]; ];

View File

@@ -1,11 +1,17 @@
import {create} from "zustand"; import {create} from "zustand";
type User = { type User = {
id: number; user_id: string;
email: string;
username: string; username: string;
roles: keyof Roles[];
role: string; role: string;
}; };
interface Roles {
role: string;
}
export type SessionState = { export type SessionState = {
user: User | null; user: User | null;
token: string | null; token: string | null;

View File

@@ -0,0 +1,48 @@
import {create} from "zustand";
import {useSessionStore} from "./sessionStore";
//import useSWR from "swr";
interface Modules {
module_id: string;
name: string;
active: boolean;
roles: string;
add_user: string;
add_date: Date;
upd_user: string;
upd_date: Date;
}
interface SettingState {
userRoles: Modules[];
fetchUserRoles: () => Promise<void>;
setUserRoles: (userRoles: Modules[]) => void;
}
interface FetchModulesResponse {
data: Modules[];
}
export const useModuleStore = create<SettingState>()((set) => ({
userRoles: [],
setUserRoles: (userRoles) => set({userRoles}),
fetchUserRoles: async () => {
try {
//const response = await axios.get<{data: Setting[]}>(`${process.env.NEXT_PUBLIC_URL}/api/settings/client`);
const {token} = useSessionStore();
const response = await fetch(`/api/auth/getuseraccess`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authentication: `Beaer ${token}`,
// You can add other headers here if necessary
},
});
const data: FetchModulesResponse = await response.json();
//console.log(data);
set({userRoles: data.data});
} catch (error) {
console.error("Failed to fetch settings:", error);
}
},
}));

View File

@@ -1,16 +1,17 @@
import {Modules} from "@/types/modules";
import {create} from "zustand"; import {create} from "zustand";
//import useSWR from "swr"; //import useSWR from "swr";
interface Modules { // interface Modules {
module_id: string; // module_id: string;
name: string; // name: string;
active: boolean; // active: boolean;
roles: string; // roles: string;
add_user: string; // add_user: string;
add_date: Date; // add_date: Date;
upd_user: string; // upd_user: string;
upd_date: Date; // upd_date: Date;
} // }
interface SettingState { interface SettingState {
modules: Modules[]; modules: Modules[];

View File

@@ -1,4 +1,4 @@
import {StrictMode} from "react"; import React from "react";
import ReactDOM from "react-dom/client"; import ReactDOM from "react-dom/client";
import "./styles.css"; import "./styles.css";
import {RouterProvider, createRouter} from "@tanstack/react-router"; import {RouterProvider, createRouter} from "@tanstack/react-router";
@@ -19,15 +19,23 @@ declare module "@tanstack/react-router" {
} }
} }
// Render the app ReactDOM.createRoot(document.getElementById("root")!).render(
const rootElement = document.getElementById("root")!; <React.StrictMode>
if (!rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement);
root.render(
<StrictMode>
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<RouterProvider router={router} /> <RouterProvider router={router} />
</QueryClientProvider> </QueryClientProvider>
</StrictMode> </React.StrictMode>
); );
}
// // Render the app
// const rootElement = document.getElementById("root")!;
// if (!rootElement.innerHTML) {
// const root = ReactDOM.createRoot(rootElement);
// root.render(
// <StrictMode>
// <QueryClientProvider client={queryClient}>
// <RouterProvider router={router} />
// </QueryClientProvider>
// </StrictMode>
// );
// }

View File

@@ -0,0 +1,10 @@
export interface Modules {
module_id: string;
name: string;
active: boolean;
roles: string;
add_User: string;
add_Date: Date;
upd_user: string;
upd_date: Date;
}

View File

@@ -19,5 +19,5 @@ import {useModuleStore} from "../lib/store/useModuleStore";
export function moduleActive(moduleName: string): boolean { export function moduleActive(moduleName: string): boolean {
const {modules} = useModuleStore(); const {modules} = useModuleStore();
const module = modules.find((m: any) => m.name === moduleName); const module = modules.find((m: any) => m.name === moduleName);
return module ? module.active : false; return module ? true : false;
} }

View File

@@ -1,52 +1,25 @@
interface User { import {Modules} from "@/types/modules";
id: number;
type User = {
user_id: string;
email: string;
username: string; username: string;
role: keyof Roles; roles: keyof Roles[];
} role: string;
};
interface Roles { interface Roles {
[roleName: string]: RolePermissions; role: string;
} }
interface RolePermissions {
[moduleName: string]: Feature[];
}
type Feature = string;
const rolePermissions: Roles = {
admin: {
production: ["view", "manage", "update", "admin"],
logistics: ["view", "manage", "update", "admin"],
quality: ["view", "request", "manage", "update", "admin"],
forklift: ["view", "manage", "update", "admin"],
admin: ["view", "view_logs", "manage", "update", "admin"],
},
manager: {
production: ["view", "manage"],
logistics: ["view", "manage"],
quality: ["view", "manage"],
forklift: ["view", "manage"],
admin: ["view_logs"],
},
supervisor: {
production: ["view", "update"],
logistics: ["view", "update"],
quality: ["view", "update"],
forklift: ["view"],
admin: [],
},
user: {
production: ["view"],
logistics: ["view"],
quality: ["view"],
forklift: [],
admin: [],
},
};
// user will need access to the module. // user will need access to the module.
// users role will determine there visual access // users role will determine there visual access
export function hasAccess(user: User | null, moduleName: string, feature: Feature): boolean { export function hasAccess(user: User | null, moduleName: string | null, modules: Modules[]): boolean {
return user?.role ? rolePermissions[user.role]?.[moduleName]?.includes(feature) || false : false; // get the modules for the id
const filteredModule = modules?.filter((f) => f.name === moduleName);
console.log(filteredModule);
// userroles and filter out by the module id,
console.log(user);
return false;
} }

View File

@@ -6,7 +6,7 @@ import path from "path";
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react(), tailwindcss(), TanStackRouterVite({autoCodeSplitting: true})], plugins: [react(), tailwindcss(), TanStackRouterVite({target: "react", autoCodeSplitting: true})],
resolve: { resolve: {
alias: { alias: {
"@": path.resolve(__dirname, "./src"), "@": path.resolve(__dirname, "./src"),

4598
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,13 +4,13 @@
"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/src/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",
"build": "npm run build:server && npm run build:frontend", "build": "npm run build:server && npm run build:frontend",
"build:server": "cd server && npm run build", "build:server": "rimraf dist && tsc --build",
"build:frontend": "cd frontend && npm run build", "build:frontend": "cd frontend && npm run build",
"start": "npm run start:server", "start": "npm run start:server",
"start:server": "cd server && npm start", "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",
"deploy": "standard-version --conventional-commits", "deploy": "standard-version --conventional-commits",
@@ -18,9 +18,19 @@
}, },
"dependencies": { "dependencies": {
"@dotenvx/dotenvx": "^1.38.3", "@dotenvx/dotenvx": "^1.38.3",
"hono": "^4.7.2", "@hono/node-server": "^1.13.8",
"@hono/zod-openapi": "^0.18.4",
"@scalar/hono-api-reference": "^0.5.175",
"@types/jsonwebtoken": "^9.0.8",
"axios": "^1.7.9",
"bcrypt": "^5.1.1",
"compression": "^1.8.0",
"cookie": "^1.0.2",
"date-fns": "^4.1.0",
"dotenv": "^16.4.7",
"drizzle-orm": "^0.39.3", "drizzle-orm": "^0.39.3",
"drizzle-zod": "^0.7.0", "drizzle-zod": "^0.7.0",
"jsonwebtoken": "^9.0.2",
"pg": "^8.13.3", "pg": "^8.13.3",
"postgres": "^3.4.5", "postgres": "^3.4.5",
"zod": "^3.24.2" "zod": "^3.24.2"

View File

@@ -1,8 +0,0 @@
```
npm install
npm run dev
```
```
open http://localhost:3000
```

View File

@@ -4,8 +4,8 @@ import {serveStatic} from "@hono/node-server/serve-static";
import {logger} from "hono/logger"; import {logger} from "hono/logger";
import {cors} from "hono/cors"; import {cors} from "hono/cors";
import {db} from "../../database/dbclient.js"; import {db} from "../database/dbclient.js";
import {modules} from "../../database/schema/modules.js"; import {modules} from "../database/schema/modules.js";
// custom routes // custom routes
import scalar from "./services/general/route/scalar.js"; import scalar from "./services/general/route/scalar.js";
@@ -44,7 +44,7 @@ const routes = [
system, system,
] as const; ] as const;
routes.forEach((route) => { const appRoutes = routes.forEach((route) => {
app.route("/api/", route); app.route("/api/", route);
}); });
@@ -57,8 +57,8 @@ app.all("/ocme/*", async (c) => {
}); });
// front end static files // front end static files
app.get("*", serveStatic({root: "../frontend/dist"})); app.use("/*", serveStatic({root: "./frontend/dist"}));
app.get("*", serveStatic({path: "../frontend/dist/index.html"})); app.use("*", serveStatic({path: "./frontend/dist/index.html"}));
serve( serve(
{ {
@@ -69,3 +69,5 @@ serve(
console.log(`Server is running on http://localhost:${info.port}`); console.log(`Server is running on http://localhost:${info.port}`);
} }
); );
export type AppRoutes = typeof appRoutes;

2123
server/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,31 +0,0 @@
{
"name": "server",
"type": "module",
"scripts": {
"dev": "dotenvx run -f ../.env -- tsx watch src/index.ts",
"build": "rimraf dist && tsc --build",
"start": "dotenvx run node dist/server/src/index.js"
},
"dependencies": {
"@hono/node-server": "^1.13.8",
"@dotenvx/dotenvx": "^1.35.0",
"@hono/zod-openapi": "^0.18.4",
"@scalar/hono-api-reference": "^0.5.175",
"@types/jsonwebtoken": "^9.0.8",
"axios": "^1.7.9",
"bcrypt": "^5.1.1",
"compression": "^1.8.0",
"cookie": "^1.0.2",
"date-fns": "^4.1.0",
"dotenv": "^16.4.7",
"drizzle-orm": "^0.39.3",
"drizzle-zod": "^0.7.0",
"jsonwebtoken": "^9.0.2",
"pg": "^8.13.3",
"postgres": "^3.4.5",
"zod": "^3.24.2"
},
"devDependencies": {
"typescript": "~5.7.3"
}
}

View File

@@ -3,10 +3,16 @@ import {OpenAPIHono} from "@hono/zod-openapi";
import login from "./routes/login.js"; import login from "./routes/login.js";
import register from "./routes/register.js"; import register from "./routes/register.js";
import session from "./routes/session.js"; import session from "./routes/session.js";
import getAccess from "./routes/getUserRoles.js";
import {authMiddleware} from "./middleware/authMiddleware.js";
const app = new OpenAPIHono(); const app = new OpenAPIHono();
app.route("auth/login", login); app.route("auth/login", login);
app.route("auth/register", register); app.route("auth/register", register);
app.route("auth/session", session); app.route("auth/session", session);
// required to login
app.use("auth/getuseraccess", authMiddleware);
app.route("/auth/getuseraccess", getAccess);
export default app; export default app;

View File

@@ -4,8 +4,8 @@ in the login route we attach it to user under roles.
*/ */
import {eq} from "drizzle-orm"; import {eq} from "drizzle-orm";
import {db} from "../../../../../database/dbclient.js"; import {db} from "../../../../database/dbclient.js";
import {userRoles} from "../../../../../database/schema/userRoles.js"; import {userRoles} from "../../../../database/schema/userRoles.js";
export const roleCheck = async (user_id: any) => { export const roleCheck = async (user_id: any) => {
// get the user roles by the user_id // get the user roles by the user_id

View File

@@ -1,6 +1,6 @@
import jwt from "jsonwebtoken"; import jwt from "jsonwebtoken";
import {db} from "../../../../../database/dbclient.js"; import {db} from "../../../../database/dbclient.js";
import {users} from "../../../../../database/schema/users.js"; import {users} from "../../../../database/schema/users.js";
import {eq, sql} from "drizzle-orm"; import {eq, sql} from "drizzle-orm";
import {checkPassword} from "../utils/checkPassword.js"; import {checkPassword} from "../utils/checkPassword.js";
import {roleCheck} from "./getUserAccess.js"; import {roleCheck} from "./getUserAccess.js";

View File

@@ -1,5 +1,7 @@
import {type MiddlewareHandler} from "hono"; import {type MiddlewareHandler} from "hono";
import {sign, verify} from "jsonwebtoken"; import jwt from "jsonwebtoken";
const {sign, verify} = jwt;
export const authMiddleware: MiddlewareHandler = async (c, next) => { export const authMiddleware: MiddlewareHandler = async (c, next) => {
const authHeader = c.req.header("Authorization"); const authHeader = c.req.header("Authorization");

View File

@@ -0,0 +1,31 @@
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import {apiHit} from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
const responseSchema = z.object({
message: z.string().optional().openapi({example: "User Created"}),
});
app.openapi(
createRoute({
tags: ["Auth"],
summary: "Returns the useraccess table",
method: "get",
path: "/",
responses: {
200: {
content: {"application/json": {schema: responseSchema}},
description: "Retrieve the user",
},
},
}),
async (c) => {
// apit hit
apiHit(c, {endpoint: "api/auth/register"});
return c.json({message: "UserRoles coming over"});
}
);
export default app;

View File

@@ -1,6 +1,6 @@
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi"; import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import {db} from "../../../../../database/dbclient.js"; import {db} from "../../../../database/dbclient.js";
import {users} from "../../../../../database/schema/users.js"; import {users} from "../../../../database/schema/users.js";
import {apiHit} from "../../../globalUtils/apiHits.js"; import {apiHit} from "../../../globalUtils/apiHits.js";
import {createPassword} from "../utils/createPassword.js"; import {createPassword} from "../utils/createPassword.js";
import {eq} from "drizzle-orm"; import {eq} from "drizzle-orm";

View File

@@ -1,6 +1,6 @@
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi"; import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import {modules} from "../../../../../database/schema/modules.js"; import {modules} from "../../../../database/schema/modules.js";
import {db} from "../../../../../database/dbclient.js"; import {db} from "../../../../database/dbclient.js";
import {eq} from "drizzle-orm"; import {eq} from "drizzle-orm";
// Define the request body schema // Define the request body schema

View File

@@ -12,5 +12,5 @@
"outDir": "./dist", "outDir": "./dist",
"removeComments": true "removeComments": true
}, },
"exclude": ["node_modules"] "exclude": ["node_modules", "frontend"]
} }