perf(lst): more migrations
This commit is contained in:
@@ -17,11 +17,11 @@ export function AppSidebar() {
|
||||
<SidebarContent>
|
||||
<Header />
|
||||
{moduleActive("production") && <ProductionSideBar />}
|
||||
{hasAccess(user, "logistics", "view") && moduleActive("logistics") && <LogisticsSideBar />}
|
||||
{hasAccess(user, "forklift", "view") && moduleActive("forklift") && <ForkliftSideBar />}
|
||||
{hasAccess(user, "eom", "view") && moduleActive("admin") && <EomSideBar />}
|
||||
{hasAccess(user, "quality", "view") && moduleActive("quality") && <QualitySideBar />}
|
||||
{hasAccess(user, "admin", "view") && moduleActive("admin") && <AdminSideBar />}
|
||||
{moduleActive("logistics") && hasAccess(user, "logistics", "view") && <LogisticsSideBar />}
|
||||
{moduleActive("forklift") && hasAccess(user, "forklift", "view") && <ForkliftSideBar />}
|
||||
{moduleActive("admin") && hasAccess(user, "eom", "view") && <EomSideBar />}
|
||||
{moduleActive("quality") && hasAccess(user, "quality", "view") && <QualitySideBar />}
|
||||
{moduleActive("admin") && hasAccess(user, "admin", "view") && <AdminSideBar />}
|
||||
</SidebarContent>
|
||||
<SidebarFooter>
|
||||
<SidebarTrigger />
|
||||
|
||||
@@ -28,7 +28,7 @@ export const useSessionStore = create<SessionState>((set) => {
|
||||
localStorage.removeItem("auth_token");
|
||||
}
|
||||
|
||||
console.log("Setting session:", {user, token});
|
||||
//console.log("Setting session:", {user, token});
|
||||
set({user, token});
|
||||
},
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ export default defineConfig({
|
||||
},
|
||||
server: {
|
||||
proxy: {
|
||||
"/api": {target: "http://localhost:3000", changeOrigin: true},
|
||||
"/api": {target: `http://localhost:4000`, changeOrigin: true},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
"drizzle-orm": "^0.39.3",
|
||||
"drizzle-zod": "^0.7.0",
|
||||
"hono": "^4.7.1",
|
||||
"http-proxy-middleware": "^3.0.3",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"pg": "^8.13.3",
|
||||
"postgres": "^3.4.5",
|
||||
|
||||
1
server/database/migrations/0005_tough_emma_frost.sql
Normal file
1
server/database/migrations/0005_tough_emma_frost.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE "users" ADD COLUMN "role" text DEFAULT 'user' NOT NULL;
|
||||
421
server/database/migrations/meta/0005_snapshot.json
Normal file
421
server/database/migrations/meta/0005_snapshot.json
Normal file
@@ -0,0 +1,421 @@
|
||||
{
|
||||
"id": "eb681265-0d44-4a8a-acaf-840acc169228",
|
||||
"prevId": "313590a8-2068-45b5-96fc-cfa5d2b32b56",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"tables": {
|
||||
"public.modules": {
|
||||
"name": "modules",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"module_id": {
|
||||
"name": "module_id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"default": "gen_random_uuid()"
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"active": {
|
||||
"name": "active",
|
||||
"type": "boolean",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": false
|
||||
},
|
||||
"roles": {
|
||||
"name": "roles",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'[\"view\", \"systemAdmin\"]'"
|
||||
},
|
||||
"add_User": {
|
||||
"name": "add_User",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"add_Date": {
|
||||
"name": "add_Date",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
},
|
||||
"upd_User": {
|
||||
"name": "upd_User",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"upd_date": {
|
||||
"name": "upd_date",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"module_name": {
|
||||
"name": "module_name",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "name",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": true,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"policies": {},
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
},
|
||||
"public.roles": {
|
||||
"name": "roles",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"role_id": {
|
||||
"name": "role_id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"default": "gen_random_uuid()"
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"add_User": {
|
||||
"name": "add_User",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"add_Date": {
|
||||
"name": "add_Date",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
},
|
||||
"upd_User": {
|
||||
"name": "upd_User",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"upd_date": {
|
||||
"name": "upd_date",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"role_name": {
|
||||
"name": "role_name",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "name",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": true,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"policies": {},
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
},
|
||||
"public.userRoles": {
|
||||
"name": "userRoles",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "uuid",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"role_id": {
|
||||
"name": "role_id",
|
||||
"type": "uuid",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"module_id": {
|
||||
"name": "module_id",
|
||||
"type": "uuid",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"role": {
|
||||
"name": "role",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"add_User": {
|
||||
"name": "add_User",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"add_Date": {
|
||||
"name": "add_Date",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
},
|
||||
"upd_User": {
|
||||
"name": "upd_User",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"upd_date": {
|
||||
"name": "upd_date",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"user_module_unique": {
|
||||
"name": "user_module_unique",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "user_id",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
},
|
||||
{
|
||||
"expression": "module_id",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": true,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"userRoles_user_id_users_user_id_fk": {
|
||||
"name": "userRoles_user_id_users_user_id_fk",
|
||||
"tableFrom": "userRoles",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"user_id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"userRoles_role_id_roles_role_id_fk": {
|
||||
"name": "userRoles_role_id_roles_role_id_fk",
|
||||
"tableFrom": "userRoles",
|
||||
"tableTo": "roles",
|
||||
"columnsFrom": [
|
||||
"role_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"role_id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"userRoles_module_id_modules_module_id_fk": {
|
||||
"name": "userRoles_module_id_modules_module_id_fk",
|
||||
"tableFrom": "userRoles",
|
||||
"tableTo": "modules",
|
||||
"columnsFrom": [
|
||||
"module_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"module_id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"policies": {},
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
},
|
||||
"public.users": {
|
||||
"name": "users",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"default": "gen_random_uuid()"
|
||||
},
|
||||
"username": {
|
||||
"name": "username",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"email": {
|
||||
"name": "email",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"password": {
|
||||
"name": "password",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"passwordToken": {
|
||||
"name": "passwordToken",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"passwordTokenExpires": {
|
||||
"name": "passwordTokenExpires",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"active": {
|
||||
"name": "active",
|
||||
"type": "boolean",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": true
|
||||
},
|
||||
"pingcode": {
|
||||
"name": "pingcode",
|
||||
"type": "numeric",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"role": {
|
||||
"name": "role",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'user'"
|
||||
},
|
||||
"lastLogin": {
|
||||
"name": "lastLogin",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
},
|
||||
"add_User": {
|
||||
"name": "add_User",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"add_Date": {
|
||||
"name": "add_Date",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
},
|
||||
"upd_User": {
|
||||
"name": "upd_User",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"upd_date": {
|
||||
"name": "upd_date",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"username": {
|
||||
"name": "username",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "username",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": true,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"policies": {},
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
}
|
||||
},
|
||||
"enums": {},
|
||||
"schemas": {},
|
||||
"sequences": {},
|
||||
"roles": {},
|
||||
"policies": {},
|
||||
"views": {},
|
||||
"_meta": {
|
||||
"columns": {},
|
||||
"schemas": {},
|
||||
"tables": {}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,13 @@
|
||||
"when": 1740364483791,
|
||||
"tag": "0004_quick_mandrill",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 5,
|
||||
"version": "7",
|
||||
"when": 1740445275919,
|
||||
"tag": "0005_tough_emma_frost",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -13,6 +13,7 @@ export const users = pgTable(
|
||||
passwordTokenExpires: timestamp("passwordTokenExpires"),
|
||||
acitve: boolean("active").default(true).notNull(),
|
||||
pinCode: numeric("pingcode"),
|
||||
role: text("role").default("user").notNull(), // temp column while we migrate the front end
|
||||
lastLogin: timestamp("lastLogin").defaultNow(),
|
||||
add_User: text("add_User").default("LST_System").notNull(),
|
||||
add_Date: timestamp("add_Date").defaultNow(),
|
||||
|
||||
@@ -8,17 +8,18 @@ import {OpenAPIHono} from "@hono/zod-openapi";
|
||||
import auth from "./services/auth/authService";
|
||||
import scalar from "./services/general/route/scalar";
|
||||
import apiHits from "./services/general/route/apitHits";
|
||||
import getModules from "./services/general/route/getModules";
|
||||
// services
|
||||
import {ocmeService} from "./services/ocme/ocmeServer";
|
||||
import system from "./services/system/systemServer";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
app.use("*", logger());
|
||||
|
||||
const allowedOrigins = ["http://localhost:3000", "http://localhost:4000", "http://localhost:5173"];
|
||||
|
||||
app.use(
|
||||
"*",
|
||||
cors({
|
||||
origin: `http://localhost:5173`,
|
||||
origin: allowedOrigins,
|
||||
allowHeaders: ["X-Custom-Header", "Upgrade-Insecure-Requests"],
|
||||
allowMethods: ["POST", "GET", "OPTIONS"],
|
||||
exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
|
||||
@@ -36,11 +37,11 @@ app.doc("/api", {
|
||||
});
|
||||
|
||||
// as we dont want to change ocme again well use a proxy to this
|
||||
app.all("/ocme/*", async (c) => {
|
||||
return ocmeService(c);
|
||||
});
|
||||
// app.all("/ocme/*", async (c) => {
|
||||
// return ocmeService(c);
|
||||
// });
|
||||
|
||||
const routes = [scalar, auth, apiHits, getModules] as const;
|
||||
const routes = [scalar, auth, apiHits, system] as const;
|
||||
|
||||
routes.forEach((route) => {
|
||||
app.route("/api/", route);
|
||||
|
||||
@@ -15,12 +15,13 @@ export async function login(
|
||||
): Promise<{token: string; user: {user_id: string; username: string}}> {
|
||||
const user = await db.select().from(users).where(eq(users.username, username));
|
||||
|
||||
console.log(user);
|
||||
if (user.length === 0) {
|
||||
throw new Error("Invalid or Missing user");
|
||||
}
|
||||
// check the password
|
||||
const checkedPass = await checkPassword(password, user[0]?.password);
|
||||
console.log(checkedPass);
|
||||
//console.log(checkedPass);
|
||||
if (!checkedPass) {
|
||||
throw new Error("Invalid Password");
|
||||
}
|
||||
@@ -36,8 +37,9 @@ export async function login(
|
||||
username: user[0].username,
|
||||
email: user[0].email,
|
||||
roles: roles || null,
|
||||
role: user[0].role || null, // this should be removed onces full migration to v2 is completed
|
||||
};
|
||||
const token = sign({user: userData}, secret, {expiresIn: expiresIn * 60});
|
||||
|
||||
return {token, user: {user_id: user[0].user_id, username: user[0].username}};
|
||||
return {token, user: userData};
|
||||
}
|
||||
|
||||
@@ -75,7 +75,6 @@ app.openapi(route, async (c) => {
|
||||
);
|
||||
}
|
||||
|
||||
const {token, user} = await login(username.toLowerCase(), password);
|
||||
try {
|
||||
const {token, user} = await login(username.toLowerCase(), password);
|
||||
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import bcrypt from "bcrypt";
|
||||
|
||||
export const checkPassword = async (currentPassword: string, dbPassword: string) => {
|
||||
let decyptPass = "";
|
||||
try {
|
||||
decyptPass = atob(dbPassword);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
// encypt password
|
||||
const pass: string | undefined = process.env.SECRET;
|
||||
|
||||
const checked = bcrypt.compareSync(pass + currentPassword, dbPassword);
|
||||
const checked = bcrypt.compareSync(pass + currentPassword, decyptPass);
|
||||
|
||||
return checked;
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ export const createPassword = async (password: string) => {
|
||||
} else {
|
||||
pass = bcrypt.hashSync(pass + password, parseInt(salt));
|
||||
|
||||
// pass = btoa(pass);
|
||||
pass = btoa(pass);
|
||||
}
|
||||
|
||||
return pass;
|
||||
|
||||
@@ -52,11 +52,11 @@ app.get(
|
||||
baseServerURL: "https://scalar.com",
|
||||
servers: [
|
||||
{
|
||||
url: "http://usday1vms006:3000",
|
||||
url: `http://usday1vms006:${process.env.SERVER_PORT}`,
|
||||
description: "Production",
|
||||
},
|
||||
{
|
||||
url: "http://localhost:3000",
|
||||
url: `http://localhost:${process.env.SERVER_PORT}`,
|
||||
description: "dev server",
|
||||
},
|
||||
],
|
||||
|
||||
@@ -38,11 +38,6 @@ app.openapi(
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
//const data = await c.req.json();
|
||||
|
||||
//apiHit(data);
|
||||
|
||||
// get the modules that are active
|
||||
let module: any = [];
|
||||
try {
|
||||
module = await db.select().from(modules).where(eq(modules.active, true));
|
||||
7
server/src/services/system/systemServer.ts
Normal file
7
server/src/services/system/systemServer.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import {OpenAPIHono} from "@hono/zod-openapi";
|
||||
|
||||
import modules from "./route/modules";
|
||||
|
||||
const app = new OpenAPIHono().route("system/module", modules);
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user