feat(intial auth): intial auth setup for the scanner
Some checks failed
Build and Push LST Docker Image / docker (push) Has been cancelled
Some checks failed
Build and Push LST Docker Image / docker (push) Has been cancelled
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
|
||||
import * as scanUserSchema from "./schema/scanUsers.js";
|
||||
|
||||
const dbURL = `postgres://${process.env.DATABASE_USER}:${process.env.DATABASE_PASSWORD}@${process.env.DATABASE_HOST}:${process.env.DATABASE_PORT}/${process.env.DATABASE_DB}`;
|
||||
|
||||
const queryClient = postgres(dbURL, {
|
||||
@@ -13,4 +15,10 @@ const queryClient = postgres(dbURL, {
|
||||
},
|
||||
});
|
||||
|
||||
export const db = drizzle({ client: queryClient });
|
||||
//export const db = drizzle({ client: queryClient });
|
||||
|
||||
export const db = drizzle(queryClient, {
|
||||
schema: {
|
||||
...scanUserSchema,
|
||||
},
|
||||
});
|
||||
|
||||
47
backend/db/schema/scanUsers.ts
Normal file
47
backend/db/schema/scanUsers.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
boolean,
|
||||
pgEnum,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
unique,
|
||||
uuid,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
|
||||
import type z from "zod";
|
||||
|
||||
export const mobileRoleEnum = pgEnum("mobile_role", [
|
||||
"user",
|
||||
"lead",
|
||||
"manager",
|
||||
"admin",
|
||||
]);
|
||||
|
||||
export const scanUser = pgTable(
|
||||
"scan_users",
|
||||
{
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
name: text("name").notNull(), // the user that will be using the scanner
|
||||
scannerId: text("scanner_id").unique().notNull(),
|
||||
pinNumber: text("pin_number").unique().notNull(),
|
||||
pinHash: text("pin_hash").notNull(),
|
||||
excludedCommand: text("excluded_commands").default(""),
|
||||
role: mobileRoleEnum("role").notNull().default("user"),
|
||||
active: boolean("active").default(true),
|
||||
lastScan: timestamp("last_scan").defaultNow(),
|
||||
add_Date: timestamp("add_Date").defaultNow(),
|
||||
upd_date: timestamp("upd_date").defaultNow(),
|
||||
},
|
||||
(table) => ({
|
||||
userNotificationUnique: unique("scan_user_unique").on(
|
||||
table.scannerId,
|
||||
table.pinNumber,
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
export const scanUserSchema = createSelectSchema(scanUser);
|
||||
export const newsSanUserSchema = createInsertSchema(scanUser);
|
||||
|
||||
export type ScanUser = z.infer<typeof scanUserSchema>;
|
||||
export type NewScanUser = z.infer<typeof newsSanUserSchema>;
|
||||
Reference in New Issue
Block a user