feat(lstv2 move): moved lstv2 into this app to keep them combined and easier to maintain

This commit is contained in:
2025-09-19 22:22:05 -05:00
parent caf2315191
commit e4477402ad
847 changed files with 165801 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
import {
text,
pgTable,
numeric,
index,
timestamp,
boolean,
uuid,
uniqueIndex,
} from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
import { users } from "./users.js";
import { roles } from "./roles.js";
import { modules } from "./modules.js";
/*
we will add the user
the module they have access to
and there role for this module. default will be user role, and view for production.
systemAdmin will just get admin to all modules.
*/
export const userRoles = pgTable(
"userRoles",
{
user_id: uuid("user_id")
.notNull()
.references(() => users.user_id, { onDelete: "cascade" }),
role_id: uuid("role_id")
.notNull()
.references(() => roles.role_id),
module_id: uuid("module_id")
.notNull()
.references(() => modules.module_id),
role: text("role").notNull(), // "view", "technician", "supervisor","manager", "admin", "systemAdmin"
add_User: text("add_User").default("LST_System").notNull(),
add_Date: timestamp("add_Date").defaultNow(),
upd_user: text("upd_User").default("LST_System").notNull(),
upd_date: timestamp("upd_date").defaultNow(),
},
(table) => {
// ensures only one user gets permissions to one role
return [
uniqueIndex("user_module_unique").on(
table.user_id,
table.module_id
),
];
}
);
// Schema for inserting a user - can be used to validate API requests
// export const insertUserRolesSchema = createInsertSchema(userRoles, {
// role: z.string().min(3, {message: "Role must be at least 3 characters"}),
// });
// Schema for selecting a Expenses - can be used to validate API responses
export const selectUserRolesSchema = createSelectSchema(userRoles);