refactor(lst): refactored to be back to npm from bun

This commit is contained in:
2025-02-27 08:36:05 -06:00
parent 4c73fb0317
commit 379f7b836d
75 changed files with 15693 additions and 2705 deletions

View File

@@ -0,0 +1,28 @@
import {text, pgTable, numeric, index, timestamp, boolean, uuid, uniqueIndex} from "drizzle-orm/pg-core";
import {createInsertSchema, createSelectSchema} from "drizzle-zod";
import {z} from "zod";
export const modules = pgTable(
"modules",
{
module_id: uuid("module_id").defaultRandom().primaryKey(),
name: text("name").notNull(),
active: boolean("active").default(false),
roles: text("roles").notNull().default(`["view", "systemAdmin"]`), // ["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) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
uniqueIndex("module_name").on(table.name),
]
);
// Schema for inserting a user - can be used to validate API requests
// export const insertModuleSchema = createInsertSchema(modules, {
// name: z.string().min(3, {message: "Module name should be longer than 3 letters"}),
// });
// Schema for selecting a Expenses - can be used to validate API responses
export const selectModuleSchema = createSelectSchema(modules);

26
database/schema/roles.ts Normal file
View File

@@ -0,0 +1,26 @@
import {text, pgTable, numeric, index, timestamp, boolean, uuid, uniqueIndex} from "drizzle-orm/pg-core";
import {createInsertSchema, createSelectSchema} from "drizzle-zod";
import {z} from "zod";
export const roles = pgTable(
"roles",
{
role_id: uuid("role_id").defaultRandom().primaryKey(),
name: text("name").notNull(),
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) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
uniqueIndex("role_name").on(table.name),
]
);
// Schema for inserting a user - can be used to validate API requests
// export const insertRolesSchema = createInsertSchema(roles, {
// name: z.string().min(3, {message: "Role name must be more than 3 letters"}),
// });
// Schema for selecting a Expenses - can be used to validate API responses
export const selectRolesSchema = createSelectSchema(roles);

View 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);

36
database/schema/users.ts Normal file
View File

@@ -0,0 +1,36 @@
import {text, pgTable, numeric, index, timestamp, boolean, uuid, uniqueIndex} from "drizzle-orm/pg-core";
import {createInsertSchema, createSelectSchema} from "drizzle-zod";
import {z} from "zod";
export const users = pgTable(
"users",
{
user_id: uuid("user_id").defaultRandom().primaryKey(),
username: text("username").notNull(),
email: text("email").notNull(),
password: text("password").notNull(),
passwordToken: text("passwordToken"),
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(),
upd_user: text("upd_User").default("LST_System").notNull(),
upd_date: timestamp("upd_date").defaultNow(),
},
(table) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
uniqueIndex("username").on(table.username),
]
);
// Schema for inserting a user - can be used to validate API requests
export const insertUsersSchema = createInsertSchema(users, {
username: z.string().min(3, {message: "Username must be at least 3 characters"}),
email: z.string().email({message: "Invalid email"}),
password: z.string().min(8, {message: "Password must be at least 8 characters"}),
});
// Schema for selecting a Expenses - can be used to validate API responses
export const selectUsersSchema = createSelectSchema(users);