feat(ocp): added labeling logs in
This commit is contained in:
4
database/migrations/0030_conscious_cable.sql
Normal file
4
database/migrations/0030_conscious_cable.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
CREATE TABLE "prodlabels" (
|
||||||
|
"label_id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||||
|
"runningNr" integer NOT NULL
|
||||||
|
);
|
||||||
7
database/migrations/0031_loud_alex_power.sql
Normal file
7
database/migrations/0031_loud_alex_power.sql
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
ALTER TABLE "prodlabels" ADD COLUMN "printerID" integer;--> statement-breakpoint
|
||||||
|
ALTER TABLE "prodlabels" ADD COLUMN "printerName" text;--> statement-breakpoint
|
||||||
|
ALTER TABLE "prodlabels" ADD COLUMN "line" integer;--> statement-breakpoint
|
||||||
|
ALTER TABLE "prodlabels" ADD COLUMN "status" text;--> statement-breakpoint
|
||||||
|
ALTER TABLE "prodlabels" ADD COLUMN "add_date" timestamp;--> statement-breakpoint
|
||||||
|
ALTER TABLE "prodlabels" ADD COLUMN "upd_date" timestamp;--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX "runningNr" ON "prodlabels" USING btree ("runningNr");
|
||||||
1194
database/migrations/meta/0030_snapshot.json
Normal file
1194
database/migrations/meta/0030_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1246
database/migrations/meta/0031_snapshot.json
Normal file
1246
database/migrations/meta/0031_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -211,6 +211,20 @@
|
|||||||
"when": 1742917978318,
|
"when": 1742917978318,
|
||||||
"tag": "0029_giant_blue_blade",
|
"tag": "0029_giant_blue_blade",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 30,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1742938986653,
|
||||||
|
"tag": "0030_conscious_cable",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 31,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1742939306614,
|
||||||
|
"tag": "0031_loud_alex_power",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
29
database/schema/prodLabels.ts
Normal file
29
database/schema/prodLabels.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
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_date: timestamp("add_date"),
|
||||||
|
upd_date: timestamp("upd_date"),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
//uniqueIndex("emailUniqueIndex").on(sql`lower(${table.email})`),
|
||||||
|
uniqueIndex("runningNr").on(table.runningNr),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
export const prodlabelsSchema = createSelectSchema(prodlabels);
|
||||||
@@ -1,23 +1,30 @@
|
|||||||
import {LstCard} from "@/components/extendedUI/LstCard";
|
import { LstCard } from "@/components/extendedUI/LstCard";
|
||||||
|
|
||||||
import {Skeleton} from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow} from "@/components/ui/table";
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
// import {useSessionStore} from "@/lib/store/sessionStore";
|
// import {useSessionStore} from "@/lib/store/sessionStore";
|
||||||
// import {useSettingStore} from "@/lib/store/useSettings";
|
// import {useSettingStore} from "@/lib/store/useSettings";
|
||||||
import {useQuery} from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import {getlabels} from "@/utils/querys/production/labels";
|
import { getlabels } from "@/utils/querys/production/labels";
|
||||||
import {format} from "date-fns";
|
import { format } from "date-fns";
|
||||||
|
|
||||||
const labelLogs = [
|
const labelLogs = [
|
||||||
{key: "line", label: "Line"},
|
{ key: "line", label: "Line" },
|
||||||
{key: "printerName", label: "Printer"},
|
{ key: "printerName", label: "Printer" },
|
||||||
{key: "runningNr", label: "Running #"},
|
{ key: "runningNr", label: "Running #" },
|
||||||
{key: "upd_date", label: "Label date"},
|
{ key: "upd_date", label: "Label date" },
|
||||||
{key: "status", label: "Label Status"},
|
{ key: "status", label: "Label Status" },
|
||||||
//{key: "reprint", label: "Reprint"}, // removing the reprint button for now until repritning is working as intended
|
//{key: "reprint", label: "Reprint"}, // removing the reprint button for now until repritning is working as intended
|
||||||
];
|
];
|
||||||
export default function LabelLog() {
|
export default function LabelLog() {
|
||||||
const {data, isError, isLoading} = useQuery(getlabels("4"));
|
const { data, isError, isLoading } = useQuery(getlabels("4"));
|
||||||
//const {user} = useSessionStore();
|
//const {user} = useSessionStore();
|
||||||
//const {settings} = useSettingStore();
|
//const {settings} = useSettingStore();
|
||||||
//const server = settings.filter((n) => n.name === "server")[0]?.value || "";
|
//const server = settings.filter((n) => n.name === "server")[0]?.value || "";
|
||||||
@@ -40,26 +47,26 @@ export default function LabelLog() {
|
|||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{Array(7)
|
{Array(7)
|
||||||
.fill(0)
|
.fill(0)
|
||||||
.map((_, i) => (
|
.map((_, i) => (
|
||||||
<TableRow key={i}>
|
<TableRow key={i}>
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">
|
||||||
<Skeleton className="h-4" />
|
<Skeleton className="h-4" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Skeleton className="h-4" />
|
<Skeleton className="h-4" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Skeleton className="h-4" />
|
<Skeleton className="h-4" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Skeleton className="h-4" />
|
<Skeleton className="h-4" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Skeleton className="h-4" />
|
<Skeleton className="h-4" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</LstCard>
|
</LstCard>
|
||||||
@@ -82,39 +89,47 @@ export default function LabelLog() {
|
|||||||
<>
|
<>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{Array(7)
|
{Array(7)
|
||||||
.fill(0)
|
.fill(0)
|
||||||
.map((_, i) => (
|
.map((_, i) => (
|
||||||
<TableRow key={i}>
|
<TableRow key={i}>
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">
|
||||||
<Skeleton className="h-4" />
|
<Skeleton className="h-4" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Skeleton className="h-4" />
|
<Skeleton className="h-4" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Skeleton className="h-4" />
|
<Skeleton className="h-4" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Skeleton className="h-4" />
|
<Skeleton className="h-4" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Skeleton className="h-4" />
|
<Skeleton className="h-4" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data?.map((label: any) => (
|
{data?.map((label: any) => (
|
||||||
<TableRow key={label.runningNr}>
|
<TableRow key={label.runningNr}>
|
||||||
<TableCell className="font-medium">{label.line}</TableCell>
|
<TableCell className="font-medium">
|
||||||
<TableCell className="font-medium">{label.printerName}</TableCell>
|
{label.line}
|
||||||
<TableCell className="font-medium">{label.runningNr}</TableCell>
|
</TableCell>
|
||||||
|
<TableCell className="font-medium">
|
||||||
|
{label.printerName}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="font-medium">
|
||||||
|
{label.runningNr}
|
||||||
|
</TableCell>
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">
|
||||||
{format(label.upd_date, "M/d/yyyy hh:mm")}
|
{format(label.upd_date, "M/d/yyyy hh:mm")}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="font-medium">{label.status}</TableCell>
|
<TableCell className="font-medium">
|
||||||
|
{label.status}
|
||||||
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {queryOptions} from "@tanstack/react-query";
|
import { queryOptions } from "@tanstack/react-query";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
export function getlabels(hours: string) {
|
export function getlabels(hours: string) {
|
||||||
@@ -13,7 +13,7 @@ export function getlabels(hours: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fetchSettings = async (hours: string) => {
|
const fetchSettings = async (hours: string) => {
|
||||||
const {data} = await axios.get(`/api/v1/ocp/labels?hours=${hours}`);
|
const { data } = await axios.get(`/api/ocp/getlabels?hours=${hours}`);
|
||||||
// if we are not localhost ignore the devDir setting.
|
// if we are not localhost ignore the devDir setting.
|
||||||
//const url: string = window.location.host.split(":")[0];
|
//const url: string = window.location.host.split(":")[0];
|
||||||
return data.data ?? [];
|
return data.data ?? [];
|
||||||
|
|||||||
32
server/services/ocp/controller/labeling/getLabels.ts
Normal file
32
server/services/ocp/controller/labeling/getLabels.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { desc, lte, sql } from "drizzle-orm";
|
||||||
|
import { db } from "../../../../../database/dbclient.js";
|
||||||
|
import { prodlabels } from "../../../../../database/schema/prodLabels.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
export const getLabels = async (hours: string) => {
|
||||||
|
const { data: labelInfo, error: labelError } = await tryCatch(
|
||||||
|
db
|
||||||
|
.select()
|
||||||
|
.from(prodlabels)
|
||||||
|
.where(
|
||||||
|
lte(
|
||||||
|
prodlabels.upd_date,
|
||||||
|
sql.raw(`NOW() - INTERVAL '${hours} hours'`)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.orderBy(desc(prodlabels.upd_date))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (labelError) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "There was an error getting the labels",
|
||||||
|
data: labelError,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Current labels order by upd_Date.",
|
||||||
|
data: labelInfo,
|
||||||
|
};
|
||||||
|
};
|
||||||
37
server/services/ocp/routes/labeling/getLabels.ts
Normal file
37
server/services/ocp/routes/labeling/getLabels.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
// an external way to creating logs
|
||||||
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { getLabels } from "../../controller/labeling/getLabels.js";
|
||||||
|
|
||||||
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["ocp"],
|
||||||
|
summary: "Returns current active lots that are tech released",
|
||||||
|
method: "get",
|
||||||
|
path: "/getlabels",
|
||||||
|
responses: responses(),
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
const hours = c.req.query("hours");
|
||||||
|
const { data: labelData, error: labelError } = await tryCatch(
|
||||||
|
getLabels(hours ?? "2")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (labelError) {
|
||||||
|
return c.json({
|
||||||
|
success: false,
|
||||||
|
message: "There was an error getting the printers",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({
|
||||||
|
success: labelData.success,
|
||||||
|
message: labelData.message,
|
||||||
|
data: labelData.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export default app;
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "nodenext",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"verbatimModuleSyntax": true,
|
"verbatimModuleSyntax": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"types": ["node"],
|
"types": ["node"],
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"jsxImportSource": "hono/jsx",
|
"jsxImportSource": "hono/jsx",
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"removeComments": true,
|
"removeComments": true,
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"resolveJsonModule": true
|
"resolveJsonModule": true
|
||||||
},
|
},
|
||||||
"include": ["server", "scripts/**/*.ts"],
|
"include": ["server", "scripts/**/*.ts"],
|
||||||
"exclude": ["node_modules", "frontend", "dist", "testFiles"]
|
"exclude": ["node_modules", "frontend", "dist", "testFiles"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user