refactor(lst): refactored to be back to npm from bun
This commit is contained in:
45
database/schema/userRoles.ts
Normal file
45
database/schema/userRoles.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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";
|
||||
import {roles} from "./roles";
|
||||
import {modules} from "./modules";
|
||||
|
||||
/*
|
||||
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),
|
||||
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);
|
||||
Reference in New Issue
Block a user