fix(misc): changes to several files for formatting
This commit is contained in:
@@ -50,7 +50,7 @@ export const schedulerManager = async () => {
|
|||||||
//console.log(data);
|
//console.log(data);
|
||||||
|
|
||||||
if (orderData.length === 0) {
|
if (orderData.length === 0) {
|
||||||
log.info({}, "There are no new orders or incoming to be updated");
|
log.debug({}, "There are no new orders or incoming to be updated");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
app/src/pkg/db/schema/prodPermission.ts
Normal file
27
app/src/pkg/db/schema/prodPermission.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import {
|
||||||
|
jsonb,
|
||||||
|
pgTable,
|
||||||
|
text,
|
||||||
|
timestamp,
|
||||||
|
uniqueIndex,
|
||||||
|
uuid,
|
||||||
|
} from "drizzle-orm/pg-core";
|
||||||
|
|
||||||
|
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),
|
||||||
|
],
|
||||||
|
);
|
||||||
@@ -1,90 +1,92 @@
|
|||||||
import type { Request, Response, NextFunction } from "express";
|
|
||||||
import { auth } from "../auth/auth.js";
|
|
||||||
import { userRoles, type UserRole } from "../db/schema/user_roles.js";
|
|
||||||
import { db } from "../db/db.js";
|
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
import type { NextFunction, Request, Response } from "express";
|
||||||
|
import { auth } from "../auth/auth.js";
|
||||||
|
import { db } from "../db/db.js";
|
||||||
|
import { type UserRole, userRoles } from "../db/schema/user_roles.js";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace Express {
|
namespace Express {
|
||||||
interface Request {
|
interface Request {
|
||||||
user?: {
|
user?: {
|
||||||
id: string;
|
id: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
roles: Record<string, string[]>;
|
roles: Record<string, string[]>;
|
||||||
};
|
username?: string | null;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function toWebHeaders(nodeHeaders: Request["headers"]): Headers {
|
function toWebHeaders(nodeHeaders: Request["headers"]): Headers {
|
||||||
const h = new Headers();
|
const h = new Headers();
|
||||||
for (const [key, value] of Object.entries(nodeHeaders)) {
|
for (const [key, value] of Object.entries(nodeHeaders)) {
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
value.forEach((v) => h.append(key, v));
|
value.forEach((v) => h.append(key, v));
|
||||||
} else if (value !== undefined) {
|
} else if (value !== undefined) {
|
||||||
h.set(key, value);
|
h.set(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const requireAuth = (moduleName?: string, requiredRoles?: string[]) => {
|
export const requireAuth = (moduleName?: string, requiredRoles?: string[]) => {
|
||||||
return async (req: Request, res: Response, next: NextFunction) => {
|
return async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
const headers = toWebHeaders(req.headers);
|
const headers = toWebHeaders(req.headers);
|
||||||
|
|
||||||
// Get session
|
// Get session
|
||||||
const session = await auth.api.getSession({
|
const session = await auth.api.getSession({
|
||||||
headers,
|
headers,
|
||||||
query: { disableCookieCache: true },
|
query: { disableCookieCache: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
return res.status(401).json({ error: "No active session" });
|
return res.status(401).json({ error: "No active session" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const userId = session.user.id;
|
const userId = session.user.id;
|
||||||
|
|
||||||
// Get roles
|
// Get roles
|
||||||
const roles = await db
|
const roles = await db
|
||||||
.select()
|
.select()
|
||||||
.from(userRoles)
|
.from(userRoles)
|
||||||
.where(eq(userRoles.userId, userId));
|
.where(eq(userRoles.userId, userId));
|
||||||
|
|
||||||
// Organize roles by module
|
// Organize roles by module
|
||||||
const rolesByModule: Record<string, string[]> = {};
|
const rolesByModule: Record<string, string[]> = {};
|
||||||
for (const r of roles) {
|
for (const r of roles) {
|
||||||
if (!rolesByModule[r.module]) rolesByModule[r.module] = [];
|
if (!rolesByModule[r.module]) rolesByModule[r.module] = [];
|
||||||
rolesByModule[r.module].push(r.role);
|
rolesByModule[r.module].push(r.role);
|
||||||
}
|
}
|
||||||
|
|
||||||
req.user = {
|
req.user = {
|
||||||
id: userId,
|
id: userId,
|
||||||
email: session.user.email,
|
email: session.user.email,
|
||||||
roles: rolesByModule,
|
roles: rolesByModule,
|
||||||
};
|
username: session.user.username,
|
||||||
|
};
|
||||||
|
|
||||||
// SystemAdmin override
|
// SystemAdmin override
|
||||||
const hasSystemAdmin = Object.values(rolesByModule)
|
const hasSystemAdmin = Object.values(rolesByModule)
|
||||||
.flat()
|
.flat()
|
||||||
.includes("systemAdmin");
|
.includes("systemAdmin");
|
||||||
|
|
||||||
// Role check (skip if systemAdmin)
|
// Role check (skip if systemAdmin)
|
||||||
if (requiredRoles?.length && !hasSystemAdmin) {
|
if (requiredRoles?.length && !hasSystemAdmin) {
|
||||||
const moduleRoles = moduleName
|
const moduleRoles = moduleName
|
||||||
? rolesByModule[moduleName] ?? []
|
? (rolesByModule[moduleName] ?? [])
|
||||||
: Object.values(rolesByModule).flat();
|
: Object.values(rolesByModule).flat();
|
||||||
const hasAccess = moduleRoles.some((role) =>
|
const hasAccess = moduleRoles.some((role) =>
|
||||||
requiredRoles.includes(role)
|
requiredRoles.includes(role),
|
||||||
);
|
);
|
||||||
if (!hasAccess) {
|
if (!hasAccess) {
|
||||||
return res.status(403).json({ error: "Forbidden" });
|
return res.status(403).json({ error: "Forbidden" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Auth middleware error:", err);
|
console.error("Auth middleware error:", err);
|
||||||
res.status(500).json({ error: "Auth check failed" });
|
res.status(500).json({ error: "Auth check failed" });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,56 +1,55 @@
|
|||||||
import * as React from "react"
|
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
|
||||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
|
import * as React from "react";
|
||||||
|
import { cn } from "../../lib/utils";
|
||||||
import { cn } from "@/lib/utils"
|
|
||||||
|
|
||||||
function ScrollArea({
|
function ScrollArea({
|
||||||
className,
|
className,
|
||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
|
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
|
||||||
return (
|
return (
|
||||||
<ScrollAreaPrimitive.Root
|
<ScrollAreaPrimitive.Root
|
||||||
data-slot="scroll-area"
|
data-slot="scroll-area"
|
||||||
className={cn("relative", className)}
|
className={cn("relative", className)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<ScrollAreaPrimitive.Viewport
|
<ScrollAreaPrimitive.Viewport
|
||||||
data-slot="scroll-area-viewport"
|
data-slot="scroll-area-viewport"
|
||||||
className="focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
|
className="focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</ScrollAreaPrimitive.Viewport>
|
</ScrollAreaPrimitive.Viewport>
|
||||||
<ScrollBar />
|
<ScrollBar />
|
||||||
<ScrollAreaPrimitive.Corner />
|
<ScrollAreaPrimitive.Corner />
|
||||||
</ScrollAreaPrimitive.Root>
|
</ScrollAreaPrimitive.Root>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ScrollBar({
|
function ScrollBar({
|
||||||
className,
|
className,
|
||||||
orientation = "vertical",
|
orientation = "vertical",
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
|
}: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
|
||||||
return (
|
return (
|
||||||
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||||
data-slot="scroll-area-scrollbar"
|
data-slot="scroll-area-scrollbar"
|
||||||
orientation={orientation}
|
orientation={orientation}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex touch-none p-px transition-colors select-none",
|
"flex touch-none p-px transition-colors select-none",
|
||||||
orientation === "vertical" &&
|
orientation === "vertical" &&
|
||||||
"h-full w-2.5 border-l border-l-transparent",
|
"h-full w-2.5 border-l border-l-transparent",
|
||||||
orientation === "horizontal" &&
|
orientation === "horizontal" &&
|
||||||
"h-2.5 flex-col border-t border-t-transparent",
|
"h-2.5 flex-col border-t border-t-transparent",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<ScrollAreaPrimitive.ScrollAreaThumb
|
<ScrollAreaPrimitive.ScrollAreaThumb
|
||||||
data-slot="scroll-area-thumb"
|
data-slot="scroll-area-thumb"
|
||||||
className="bg-border relative flex-1 rounded-full"
|
className="bg-border relative flex-1 rounded-full"
|
||||||
/>
|
/>
|
||||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { ScrollArea, ScrollBar }
|
export { ScrollArea, ScrollBar };
|
||||||
|
|||||||
@@ -1,114 +1,113 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
|
import { cn } from "../../lib/utils";
|
||||||
import { cn } from "@/lib/utils"
|
|
||||||
|
|
||||||
function Table({ className, ...props }: React.ComponentProps<"table">) {
|
function Table({ className, ...props }: React.ComponentProps<"table">) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
data-slot="table-container"
|
data-slot="table-container"
|
||||||
className="relative w-full overflow-x-auto"
|
className="relative w-full overflow-x-auto"
|
||||||
>
|
>
|
||||||
<table
|
<table
|
||||||
data-slot="table"
|
data-slot="table"
|
||||||
className={cn("w-full caption-bottom text-sm", className)}
|
className={cn("w-full caption-bottom text-sm", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
||||||
return (
|
return (
|
||||||
<thead
|
<thead
|
||||||
data-slot="table-header"
|
data-slot="table-header"
|
||||||
className={cn("[&_tr]:border-b", className)}
|
className={cn("[&_tr]:border-b", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
||||||
return (
|
return (
|
||||||
<tbody
|
<tbody
|
||||||
data-slot="table-body"
|
data-slot="table-body"
|
||||||
className={cn("[&_tr:last-child]:border-0", className)}
|
className={cn("[&_tr:last-child]:border-0", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
||||||
return (
|
return (
|
||||||
<tfoot
|
<tfoot
|
||||||
data-slot="table-footer"
|
data-slot="table-footer"
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
|
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
||||||
return (
|
return (
|
||||||
<tr
|
<tr
|
||||||
data-slot="table-row"
|
data-slot="table-row"
|
||||||
className={cn(
|
className={cn(
|
||||||
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
|
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
||||||
return (
|
return (
|
||||||
<th
|
<th
|
||||||
data-slot="table-head"
|
data-slot="table-head"
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
"text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
||||||
return (
|
return (
|
||||||
<td
|
<td
|
||||||
data-slot="table-cell"
|
data-slot="table-cell"
|
||||||
className={cn(
|
className={cn(
|
||||||
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TableCaption({
|
function TableCaption({
|
||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<"caption">) {
|
}: React.ComponentProps<"caption">) {
|
||||||
return (
|
return (
|
||||||
<caption
|
<caption
|
||||||
data-slot="table-caption"
|
data-slot="table-caption"
|
||||||
className={cn("text-muted-foreground mt-4 text-sm", className)}
|
className={cn("text-muted-foreground mt-4 text-sm", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Table,
|
Table,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableFooter,
|
TableFooter,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableRow,
|
TableRow,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableCaption,
|
TableCaption,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ interface ShipmentItemProps {
|
|||||||
export function ShipmentItem({
|
export function ShipmentItem({
|
||||||
shipment,
|
shipment,
|
||||||
index = 0,
|
index = 0,
|
||||||
perm = true,
|
//perm = true,
|
||||||
}: ShipmentItemProps) {
|
}: ShipmentItemProps) {
|
||||||
const { setNodeRef, listeners, attributes, transform } = useDraggable({
|
const { setNodeRef, listeners, attributes, transform } = useDraggable({
|
||||||
id: shipment.orderNumber,
|
id: shipment.orderNumber,
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { createFileRoute } from "@tanstack/react-router";
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import { coreSocket } from "../../../lib/socket.io/socket";
|
import { coreSocket } from "../../../lib/socket.io/socket";
|
||||||
import "../-components/style.css";
|
import "../-components/style.css";
|
||||||
import moment from "moment";
|
|
||||||
import Timeline from "react-calendar-timeline";
|
|
||||||
|
|
||||||
export const Route = createFileRoute("/(logistics)/logistics/deliverySchedule")(
|
export const Route = createFileRoute("/(logistics)/logistics/deliverySchedule")(
|
||||||
{
|
{
|
||||||
@@ -19,9 +17,9 @@ export const Route = createFileRoute("/(logistics)/logistics/deliverySchedule")(
|
|||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
// connect to the channel
|
// connect to the channel
|
||||||
const [shipments, setShipments] = useState([]) as any;
|
//const [shipments, setShipments] = useState([]) as any;
|
||||||
//const [perm] = useState(true); // will check this for sure with a user permissions
|
//const [perm] = useState(true); // will check this for sure with a user permissions
|
||||||
const [loaded, setLoaded] = useState(false);
|
//const [loaded, setLoaded] = useState(false);
|
||||||
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// const handleConnect = () => {
|
// const handleConnect = () => {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { useEffect } from "react";
|
|||||||
import { Toaster } from "sonner";
|
import { Toaster } from "sonner";
|
||||||
import Nav from "../components/navBar/Nav";
|
import Nav from "../components/navBar/Nav";
|
||||||
import SideBarNav from "../components/navBar/SideBarNav";
|
import SideBarNav from "../components/navBar/SideBarNav";
|
||||||
import { SidebarProvider, SidebarTrigger } from "../components/ui/sidebar";
|
import { SidebarProvider } from "../components/ui/sidebar";
|
||||||
import { userAccess } from "../lib/authClient";
|
import { userAccess } from "../lib/authClient";
|
||||||
import { SessionGuard } from "../lib/providers/SessionProvider";
|
import { SessionGuard } from "../lib/providers/SessionProvider";
|
||||||
import { ThemeProvider } from "../lib/providers/theme-provider";
|
import { ThemeProvider } from "../lib/providers/theme-provider";
|
||||||
|
|||||||
@@ -91,6 +91,10 @@ function RouteComponent() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
// password reset will do the email flow
|
||||||
|
// change password an input for this one so well need inline editing for this dope one
|
||||||
|
// trash can to delete user
|
||||||
|
// last login -- need to get working on the server side as well.
|
||||||
columnHelper.accessor("roles", {
|
columnHelper.accessor("roles", {
|
||||||
header: () => <span>Roles</span>,
|
header: () => <span>Roles</span>,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user