feat(labeling): added printers and machine and other data for preprinting
This commit is contained in:
34
app/src/pkg/db/schema/printers.ts
Normal file
34
app/src/pkg/db/schema/printers.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
boolean,
|
||||
index,
|
||||
jsonb,
|
||||
numeric,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
uniqueIndex,
|
||||
uuid,
|
||||
} from "drizzle-orm/pg-core";
|
||||
|
||||
export const printers = pgTable(
|
||||
"printers",
|
||||
{
|
||||
printer_id: uuid("printer_id").defaultRandom().primaryKey(),
|
||||
humanReadableId: text("humanReadableId"),
|
||||
name: text("name").notNull(),
|
||||
ipAddress: text("ip_address"),
|
||||
port: numeric("port"),
|
||||
status: text("status"),
|
||||
statusText: text("status_text"),
|
||||
lastTimePrinted: timestamp("last_time_printed").notNull().defaultNow(),
|
||||
assigned: boolean("assigned").default(false),
|
||||
remark: text("remark"),
|
||||
printDelay: numeric("print_delay").default("90"),
|
||||
monitorState: boolean("monitor_state").default(false),
|
||||
processes: jsonb("processes").default([]),
|
||||
printDelayOverride: boolean("print_delay_override").default(false), // this will be more for if we have the lot time active but want to over ride this single line for some reason
|
||||
add_Date: timestamp("add_Date").defaultNow(),
|
||||
upd_date: timestamp("upd_date").defaultNow(),
|
||||
},
|
||||
(table) => [uniqueIndex("humanReadableId").on(table.humanReadableId)],
|
||||
);
|
||||
27
app/src/pkg/db/schema/prodLabels.ts
Normal file
27
app/src/pkg/db/schema/prodLabels.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import {
|
||||
integer,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
uniqueIndex,
|
||||
uuid,
|
||||
} from "drizzle-orm/pg-core";
|
||||
|
||||
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"), // printed | bookedIn | delivered | booked out
|
||||
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),
|
||||
],
|
||||
);
|
||||
9
app/src/pkg/prodSql/querys/general/machineInfo.ts
Normal file
9
app/src/pkg/prodSql/querys/general/machineInfo.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export const machineCheck = `
|
||||
SELECT [HumanReadableId]
|
||||
,[Name]
|
||||
,[Location]
|
||||
,[Active]
|
||||
,[ImportSource]
|
||||
,[StagingMainMaterialMandatory]
|
||||
FROM [test1_AlplaPROD2.0_Read].[masterData].[Machine] (nolock)
|
||||
where Active = 1 and [Location] = [loc]`;
|
||||
29
app/src/pkg/utils/getMachineInfo.ts
Normal file
29
app/src/pkg/utils/getMachineInfo.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createLogger } from "../logger/logger.js";
|
||||
import { prodQuery } from "../prodSql/prodQuery.js";
|
||||
import { machineCheck } from "../prodSql/querys/general/machineInfo.js";
|
||||
|
||||
export const getMachineData = async (machine: string) => {
|
||||
const log = createLogger({
|
||||
module: "logistics",
|
||||
subModule: "preprint",
|
||||
});
|
||||
let updateQuery = machineCheck.replaceAll("[loc]", machine!);
|
||||
|
||||
if (machine === "all") {
|
||||
updateQuery = machineCheck.replaceAll("and [Location] = [loc]", "");
|
||||
}
|
||||
|
||||
// create blank lots in case there is an error and dose not work
|
||||
let mac = [];
|
||||
|
||||
try {
|
||||
const getMac: any = await prodQuery(updateQuery, "Machine id check");
|
||||
|
||||
mac = getMac.data;
|
||||
// console.log("Machine data", mac); // removed due to swr being activated
|
||||
} catch (err) {
|
||||
log.error({ error: err }, `Error with Machine id Check query: ${err}`);
|
||||
}
|
||||
|
||||
return mac;
|
||||
};
|
||||
Reference in New Issue
Block a user