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,35 @@
import {
integer,
jsonb,
pgTable,
text,
timestamp,
uniqueIndex,
uuid,
} from "drizzle-orm/pg-core";
import { createSelectSchema } from "drizzle-zod";
export const apiHits = pgTable(
"apiHits",
{
apiHit_id: uuid("apiHit_id").defaultRandom().primaryKey(),
ip: text("ip"),
endpoint: text("endpoint"),
action: text("action"),
lastBody: jsonb("lastBody"),
stats: integer("stats").default(1),
add_date: timestamp().defaultNow(),
upd_date: timestamp().defaultNow(),
},
(table) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
uniqueIndex("endpoint").on(table.endpoint, table.ip),
]
);
// 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(apiHits);

View File

@@ -0,0 +1,25 @@
import { text, pgTable, timestamp, uuid, jsonb } from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
export const commandLog = pgTable(
"commandLog",
{
commandLog_id: uuid("commandLog_id").defaultRandom().primaryKey(),
commandUsed: text("commandUsed").notNull(),
bodySent: jsonb("bodySent").default([]),
reasonUsed: text("reasonUsed"),
add_at: timestamp("add_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(commandLog);

View File

@@ -0,0 +1,53 @@
import {
date,
integer,
pgTable,
text,
timestamp,
uuid,
} from "drizzle-orm/pg-core";
import { createSelectSchema } from "drizzle-zod";
export const eom = pgTable(
"eom",
{
eom_id: uuid("eom_id").defaultRandom().primaryKey(),
eomMonth: date("eomMonth").notNull(), // what month are we running in should just be the first of current month
plantToken: text("plantToken"),
article: text("article").notNull(),
articleDescription: text("articleDescription").notNull(),
materialType: text("materialType"),
invStart: integer("invStart"), // this will come from the previous month
invEnd: integer("invEnd"),
intransit: integer("intransit"),
// pass over a calculation for ending inv
purchase: integer("purchase"),
gpRecived: integer("gpRecived"),
// pass calcuation for difference
materialIn: integer("materialIn"), // from other alpla plants
materialOut: integer("materialOut"), // out to other alpla plants
quarantine: integer("quarantine"),
// calcualtion for actaul consumption
prodConsumption: integer("prodConsumption"),
// difference will be a calculated number
// waste will be calculated.
priceKg: text("priceKg"), // will be converted to a float and then calcuated into the data
// loss/gain calcualtion
comments: text("comments"),
weight: text("weight"), // for calculations should be converted to a float
pfc: text("pfc"), // profit center this will belong too.
upd_user: text("upd_user"),
upd_date: timestamp("upd_date"),
}
// (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(eom);

View File

@@ -0,0 +1,40 @@
import {
text,
pgTable,
numeric,
index,
timestamp,
boolean,
uuid,
uniqueIndex,
jsonb,
} from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
export const fifoIndex = pgTable(
"fifoIndex",
{
fifoIndex_id: uuid("fifoIndex_id").defaultRandom().primaryKey(),
lot: text("lot").notNull(),
av: numeric("av").notNull(),
runningNr: numeric("runningNr").notNull(),
prodDate: timestamp("prodDate").notNull(),
// currentInv: jsonb("currentInv").default([]),
fifoFollowed: boolean("fifoFollowed").notNull(),
add_Date: timestamp("add_Date").defaultNow(),
},
(table) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
// uniqueIndex("role_name").on(table.name),
uniqueIndex("fifo_runningNr").on(table.runningNr),
]
);
// 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(fifoIndex);

View File

View File

View File

View File

@@ -0,0 +1,41 @@
import {
date,
integer,
pgTable,
text,
timestamp,
uuid,
} from "drizzle-orm/pg-core";
import { createSelectSchema } from "drizzle-zod";
export const invHistoricalData = pgTable(
"invHistoricalData",
{
inv_id: uuid("inv_id").defaultRandom().primaryKey(),
histDate: date("histDate").notNull(), // this date should always be yesterday when we post it.
plantToken: text("plantToken"),
article: text("article").notNull(),
articleDescription: text("articleDescription").notNull(),
materialType: text("materialType"),
total_QTY: text("total_QTY"),
avaliable_QTY: text("avaliable_QTY"),
coa_QTY: text("coa_QTY"),
held_QTY: text("held_QTY"),
lot_Number: text("lot_number"),
consignment: text("consignment"),
location: text("location"),
upd_user: text("upd_user").default("lst"),
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(invHistoricalData);

View File

@@ -0,0 +1,37 @@
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 logs = pgTable(
"logs",
{
log_id: uuid("log_id").defaultRandom().primaryKey(),
level: text("level"),
username: text("username").default("LST_Serivce"),
service: text("service").notNull().default("system"),
message: text("message").notNull(),
checked: boolean("checked").default(false),
//checkedAt: timestamp("checkedAt"),
created_at: timestamp("add_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(logs);

View File

@@ -0,0 +1,31 @@
import {text, pgTable, timestamp, boolean, uuid, uniqueIndex, jsonb} from "drizzle-orm/pg-core";
import {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"]
roles: jsonb("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);
export type Modules = typeof modules;

View File

@@ -0,0 +1,36 @@
import {
boolean,
jsonb,
pgTable,
text,
timestamp,
uniqueIndex,
uuid,
} from "drizzle-orm/pg-core";
import { createSelectSchema } from "drizzle-zod";
export const notifications = pgTable(
"notifications",
{
notify_id: uuid("notify_id").defaultRandom().primaryKey(),
name: text("name").notNull(),
description: text("description").notNull(),
checkInterval: text("checkInterval").default("1"),
timeType: text("timeType").default("hour"),
emails: text("emails"),
active: boolean("active").default(false),
lastRan: timestamp("lastRan").defaultNow(),
notifiySettings: jsonb("notifiySettings").default({}),
},
(table) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
uniqueIndex("notify_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 selectNotificationsSchema = createSelectSchema(notifications);

View File

@@ -0,0 +1,41 @@
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 ocmeData = pgTable(
"ocmeData",
{
ocme_id: uuid("ocme_id").defaultRandom().primaryKey(),
sscc: text("sscc"),
runningNr: numeric("runningNr").notNull(),
completed: boolean("completed").default(false),
lineNum: numeric("lineNum").notNull(),
pickedUp: boolean("pickedUp").default(false),
areaFrom: text("areaFrom").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),
uniqueIndex("ocme_runningNr").on(table.runningNr),
]
);
// 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(ocmeData);

View File

@@ -0,0 +1,37 @@
import {
text,
pgTable,
numeric,
timestamp,
boolean,
uuid,
integer,
jsonb,
} from "drizzle-orm/pg-core";
import { createSelectSchema } from "drizzle-zod";
export const ocmeCycleCounts = pgTable(
"ocmeCycleCounts",
{
ocme_id: uuid("ocme_id").defaultRandom().primaryKey(),
laneId: integer("laneId").notNull(),
warehouseName: text("warehouseName").notNull(),
laneName: text("laneName").notNull(),
good: boolean("good").default(false),
cycleCount: jsonb("cycleCount").default([]),
add_User: text("add_User").default("LST_System").notNull(),
add_Date: timestamp("add_Date").defaultNow(),
},
(table) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
// uniqueIndex("role_name").on(table.name),
//uniqueIndex("ocme_runningNr").on(table.runningNr),
]
);
// 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(ocmeCycleCounts);

View File

@@ -0,0 +1,20 @@
import {text, pgTable, timestamp, uuid, integer} from "drizzle-orm/pg-core";
import {createInsertSchema, createSelectSchema} from "drizzle-zod";
import {z} from "zod";
export const manualPrinting = pgTable("manualPrinting", {
print_id: uuid("print_id").defaultRandom().primaryKey(),
line: integer("line"),
printReason: text("printReason").notNull(),
initials: text("initials").notNull(),
additionalComments: text("additionalComments").notNull(),
add_date: timestamp("add_date").defaultNow(),
add_user: text("add_user"),
});
// 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(manualPrinting);

View File

@@ -0,0 +1,45 @@
import {
text,
pgTable,
numeric,
index,
timestamp,
boolean,
uuid,
uniqueIndex,
jsonb,
} from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
export const printerData = pgTable(
"printerData",
{
printer_id: uuid("printer_id").defaultRandom().primaryKey(),
humanReadableId: text("humanReadableId"),
name: text("name").notNull(),
ipAddress: text("ipAddress"),
port: numeric("port"),
status: text("status"),
statusText: text("statusText"),
lastTimePrinted: timestamp("lastTimePrinted").notNull().defaultNow(),
assigned: boolean("assigned").default(false),
remark: text("remark"),
printDelay: numeric("printDelay").default("90"),
monitorState: boolean("monitorState").default(false),
processes: jsonb("processes").default([]),
add_Date: timestamp("add_Date").defaultNow(),
upd_date: timestamp("upd_date").defaultNow(),
},
(table) => [
//uniqueIndex("emailUniqueIndex").on(sql`lower(${table.email})`),
uniqueIndex("humanReadableId").on(table.humanReadableId),
]
);
// 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(printerData);

View File

@@ -0,0 +1,30 @@
import {
integer,
pgTable,
uuid,
uniqueIndex,
text,
timestamp,
} from "drizzle-orm/pg-core";
import { createSelectSchema } from "drizzle-zod";
export const prodlabels = pgTable(
"prodlabels",
{
label_id: uuid("label_id").defaultRandom().primaryKey(),
printerID: integer("printerID"),
printerName: text("printerName"),
line: integer("line"),
runningNr: integer("runningNr").notNull(),
status: text("status"),
add_user: text("add_user").default("lst"),
add_date: timestamp("add_date").defaultNow(),
upd_date: timestamp("upd_date").defaultNow(),
},
(table) => [
//uniqueIndex("emailUniqueIndex").on(sql`lower(${table.email})`),
uniqueIndex("runningNr").on(table.runningNr),
]
);
export const prodlabelsSchema = createSelectSchema(prodlabels);

View File

@@ -0,0 +1,38 @@
import {
text,
pgTable,
timestamp,
uuid,
uniqueIndex,
jsonb,
} from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
export const prodPermissions = pgTable(
"prodPermissions",
{
prodPerm_id: uuid("prodPerm_id").defaultRandom().primaryKey(),
name: text("name").notNull(),
description: text("description").notNull(),
roles: jsonb("roles").default([]),
rolesLegacy: jsonb("rolesLegacy").default([]),
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("prodPermName").on(table.name),
]
);
// Schema for inserting a user - can be used to validate API requests
// export const insertUsersSchema = createInsertSchema(prodPermissions, {
// name: z
// .string()
// .min(3, { message: "Role name must be longer than 3 characters" }),
// });
// Schema for selecting a Expenses - can be used to validate API responses
export const selectUsersSchema = createSelectSchema(prodPermissions);

View File

@@ -0,0 +1,48 @@
import {
text,
pgTable,
numeric,
index,
timestamp,
boolean,
uuid,
uniqueIndex,
integer,
} from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
export const qualityRequest = pgTable(
"qualityRequest",
{
request_id: uuid("request_id").defaultRandom().primaryKey(),
article: numeric("article"),
description: text("description"),
runningNr: text("runningNr"),
lotNr: numeric("lotNr"),
warehouseAtRequest: text("warehouseAtRequest"),
locationAtRequest: text("locationAtRequest"),
warehouseMovedTo: text("warehouseMovedTo"),
locationMovedTo: text("locationMovedTo"),
durationToMove: integer("durationToMove"),
locationDropOff: text("locationDropOff"),
palletStatus: integer("palletStatus"),
palletStatusText: text("palletStatusText"),
palletRequest: integer("palletRequest"),
add_date: timestamp("add_date").defaultNow(),
add_user: text("add_user").default("LST"),
upd_date: timestamp("upd_date").defaultNow(),
upd_user: text("upd_user").default("LST"),
},
(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(qualityRequest);

View File

@@ -0,0 +1,32 @@
import {
integer,
jsonb,
pgTable,
text,
timestamp,
uniqueIndex,
uuid,
} from "drizzle-orm/pg-core";
import { createSelectSchema } from "drizzle-zod";
export const labelRatio = pgTable(
"labelRatio",
{
ratio_id: uuid(" ratio_id").defaultRandom().primaryKey(),
name: text("name").default("labels"),
autoLabel: integer("autoLabel").default(0),
manualLabel: integer("manualLabel").default(0),
lastReset: timestamp().defaultNow(),
},
(table) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
uniqueIndex("labelname").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(labelRatio);

View File

@@ -0,0 +1,41 @@
import {
text,
pgTable,
numeric,
index,
timestamp,
boolean,
uuid,
uniqueIndex,
jsonb,
integer,
} from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
export const rfidReaders = pgTable(
"rfidReaders",
{
rfidReader_id: uuid("rfidReader_id").defaultRandom().primaryKey(),
reader: text("reader"),
readerIP: text("readerIP"),
lastHeartBeat: timestamp("lastHeartBeat").defaultNow(),
lastTrigger: timestamp("lastTrigger").defaultNow(),
lastTriggerGood: boolean("lastTiggerGood").default(true),
active: boolean("active").default(true),
lastTagScanned: text("lastTagScanned"),
goodReads: integer("goodReads").default(0),
badReads: integer("badReads").default(0),
},
(table) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
uniqueIndex("reader").on(table.reader),
]
);
// 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(rfidReaders);

View File

@@ -0,0 +1,38 @@
import {
text,
pgTable,
timestamp,
uuid,
uniqueIndex,
jsonb,
integer,
} from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
export const rfidTags = pgTable(
"rfidTags",
{
rfidTag_id: uuid("rfidTag_id").defaultRandom().primaryKey(),
tagHex: text("tagHex"),
tag: text("tag"),
lastRead: timestamp("lastRead").defaultNow(), // cahnge this and hope we dont loose the data.
counts: jsonb("counts").default([]), // example [{area: Line3.2, count: 1}, {area: line3.1, count: 6}]
lastareaIn: text("lastareaIn").notNull(),
runningNumber: integer("runningNumber"),
antenna: integer("antenna"),
tagStrength: integer("tagStrength"),
created_at: timestamp("created_at").defaultNow(),
},
(table) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
uniqueIndex("tagHex").on(table.tagHex),
]
);
// Schema for inserting a user - can be used to validate API requests
// export const insertRolesSchema = createInsertSchema(rfidTags, {
// tagHex: z.string().min(3, {message: "Tag Should have more than 3 characters"}),
// });
// Schema for selecting a Expenses - can be used to validate API responses
export const selectRolesSchema = createSelectSchema(rfidTags);

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,50 @@
import {
boolean,
date,
jsonb,
numeric,
pgTable,
text,
timestamp,
uniqueIndex,
uuid,
} from "drizzle-orm/pg-core";
import { createSelectSchema } from "drizzle-zod";
export const serverData = pgTable(
"serverData",
{
server_id: uuid("server_id").defaultRandom().primaryKey(),
sName: text("sName").notNull(),
serverDNS: text("serverDNS"),
plantToken: text("plantToken"),
idAddress: text("idAddress"),
greatPlainsPlantCode: numeric("greatPlainsPlantCode"),
streetAddress: text("streetAddress"),
cityState: text("cityState"),
zipcode: numeric("zipcode"),
contactEmail: text("contactEmail"),
contactPhone: text("contactPhone"),
customerTiAcc: text("customerTiAcc"),
lstServerPort: numeric("lstServerPort"),
active: boolean("active").default(true),
serverLoc: text("serverLoc"),
oldVersion: text("oldVersion"),
lastUpdated: timestamp("lastUpdated").defaultNow(),
shippingHours: text("shippingHours").default(
'[{"early": "06:30", "late": "23:00"}]'
),
tiPostTime: text("tiPostTime").default('[{"from": "24", "to": "24"}]'),
otherSettings: jsonb("otherSettings").default([
{ specialInstructions: "something for ti", active: false },
]),
isUpgrading: boolean("isUpgrading").default(false),
},
(table) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
uniqueIndex("plantToken").on(table.plantToken),
]
);
export const selectRolesSchema = createSelectSchema(serverData);

View File

@@ -0,0 +1,39 @@
import {
text,
pgTable,
timestamp,
uuid,
uniqueIndex,
jsonb,
} from "drizzle-orm/pg-core";
import { createSelectSchema } from "drizzle-zod";
import { z } from "zod";
import { modules } from "./modules.js";
export const settings = pgTable(
"settings",
{
settings_id: uuid("role_id").defaultRandom().primaryKey(),
name: text("name").notNull(),
value: text("value").notNull(),
description: text("description"),
//moduleName: text("moduleName").references(() => modules.name),
moduleName: text("moduleName"),
roles: jsonb("roles").notNull().default(["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("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(settings);

View File

@@ -0,0 +1,39 @@
import {
text,
pgTable,
numeric,
timestamp,
uuid,
integer,
} from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
export const siloAdjustments = pgTable(
"siloAdjustments",
{
siloAdjust_id: uuid("siloAdjust_id").defaultRandom().primaryKey(),
warehouseID: integer("level"),
locationID: integer("locationID"),
currentStockLevel: numeric("currentStockLevel"),
newLevel: numeric("newLevel"),
comment: text("comment").default(""),
dateAdjusted: timestamp("dateAdjusted").defaultNow(),
lastDateAdjusted: timestamp("lastDateAdjusted").defaultNow(),
commentAddedBy: text("commentAddedBy"),
commentDate: text("commentDate"),
commentKey: text("commentKey"),
add_user: text("add_user").default("LST_Serivce"),
},
(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(siloAdjustments);

View File

@@ -0,0 +1,45 @@
import {
text,
pgTable,
timestamp,
boolean,
uuid,
uniqueIndex,
jsonb,
} from "drizzle-orm/pg-core";
import { createSelectSchema } from "drizzle-zod";
//import {z} from "zod";
export const subModules = pgTable(
"subModules",
{
submodule_id: uuid("submodule_id").defaultRandom().primaryKey(),
moduleName: text("moduleName"),
// .notNull()
// .references(() => modules.name),
name: text("name").notNull(),
description: text("description"),
link: text("link").notNull(),
active: boolean("active").default(false),
roles: jsonb("roles").notNull().default(["systemAdmin"]), // ["view", "technician", "supervisor","manager", "admin","systemAdmin"]
icon: text("icon"),
subSubModule: jsonb("subSubModule").default([]),
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("subModule_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(subModules);
export type Modules = typeof subModules;

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

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