refactor(dbscheme): refactoring from opening and saving
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
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";
|
||||
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
|
||||
@@ -17,14 +26,14 @@ export const userRoles = pgTable(
|
||||
"userRoles",
|
||||
{
|
||||
user_id: uuid("user_id")
|
||||
.notNull()
|
||||
.references(() => users.user_id),
|
||||
.notNull()
|
||||
.references(() => users.user_id),
|
||||
role_id: uuid("role_id")
|
||||
.notNull()
|
||||
.references(() => roles.role_id),
|
||||
.notNull()
|
||||
.references(() => roles.role_id),
|
||||
module_id: uuid("module_id")
|
||||
.notNull()
|
||||
.references(() => modules.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(),
|
||||
@@ -33,13 +42,18 @@ export const userRoles = pgTable(
|
||||
},
|
||||
(table) => {
|
||||
// ensures only one user gets permissions to one role
|
||||
return [uniqueIndex("user_module_unique").on(table.user_id, table.module_id)];
|
||||
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"}),
|
||||
});
|
||||
// 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