feat(opendock): added in new article link setup for fine tuning how od works

This commit is contained in:
2026-05-23 11:22:02 -05:00
parent 3a27fd8542
commit 389211186f
24 changed files with 3903 additions and 72 deletions

View File

@@ -6,6 +6,7 @@ import {
type NewOpendockArticleSetup,
opendockArticleSetup,
} from "../db/schema/opendock_articleSetup.js";
import { opendockDockSetup } from "../db/schema/opendock_docks.js";
import { prodQuery } from "../prodSql/prodSqlQuery.controller.js";
import {
type SqlQuery,
@@ -34,6 +35,11 @@ const newArticleLink = z.object({
),
});
const newDockLink = z.object({
name: z.string(),
dockID: z.string(),
});
r.post("/", async (req, res) => {
try {
const validated = newArticleLink.parse(req.body) as NewOpendockArticleSetup;
@@ -190,7 +196,80 @@ r.get("/customers/:av", async (req, res) => {
module: "opendock",
subModule: "articleCheck",
message: `All customers linked to av: ${av}`,
data: data as any,
data: data?.data ?? ([] as any),
status: 200,
});
});
r.post("/dock", async (req, res) => {
try {
const validated = newDockLink.parse(req.body) as any;
const newLink = await db
.insert(opendockDockSetup)
.values({
name: validated.name,
dockID: validated.dockID,
add_user: req.user?.username ?? "lst_user",
})
.returning();
return apiReturn(res, {
success: true,
level: "info",
module: "opendock",
subModule: "articleCheck",
message: `${validated.name} was just added `,
data: newLink as any,
status: 200,
});
} catch (err) {
if (err instanceof z.ZodError) {
const flattened = z.flattenError(err);
// return res.status(400).json({
// error: "Validation failed",
// details: flattened,
// });
return apiReturn(res, {
success: false,
level: "error", //connect.success ? "info" : "error",
module: "opendock",
subModule: "articleCheck",
message: "Validation failed",
data: [flattened.fieldErrors],
status: 400, //connect.success ? 200 : 400,
});
}
return apiReturn(res, {
success: false,
level: "error", //connect.success ? "info" : "error",
module: "opendock",
subModule: "articleCheck",
message: "Internal Server Error adding dock link",
data: [err],
status: 400, //connect.success ? 200 : 400,
});
}
});
r.get("/dock", async (_, res) => {
const { data } = await tryCatch(
db
.select()
.from(opendockDockSetup)
.orderBy(desc(opendockDockSetup.name))
.limit(1500),
);
return apiReturn(res, {
success: true,
level: "info",
module: "opendock",
subModule: "articleCheck",
message: `All dock links`,
data: data ?? [],
status: 200,
});
});