feat(eom): all endpoints created for the eom template to run in all plants

This commit is contained in:
2025-09-30 19:55:35 -05:00
parent a7f45abfeb
commit 9a14f250b6
25 changed files with 872 additions and 33 deletions

View File

@@ -1,7 +1,11 @@
import { eq } from "drizzle-orm";
import { db } from "../../../../database/dbclient.js";
import { settings } from "../../../../database/schema/settings.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { query } from "../../sqlServer/prodSqlServer.js";
import { activeArticle } from "../../sqlServer/querys/dataMart/article.js";
export const getActiveAv = async () => {
export const getActiveAv = async (includePlantToken: boolean = false) => {
let articles: any = [];
try {
const res = await query(activeArticle, "Get active articles");
@@ -10,5 +14,20 @@ export const getActiveAv = async () => {
articles = error;
}
return articles;
if (includePlantToken) {
const { data, error } = (await tryCatch(
db.select().from(settings).where(eq(settings.name, "plantToken"))
)) as any;
if (error) {
console.log("Error getting articles");
return articles;
}
return articles.map((n: any) => {
return { plantToken: data[0].value, ...n };
});
} else {
return articles;
}
};

View File

@@ -5,7 +5,10 @@ import {
totalInvRn,
} from "../../sqlServer/querys/dataMart/totalINV.js";
export const getINV = async (rn: boolean) => {
export const getINV = async (
rn: boolean,
includePlantToken: boolean = false
) => {
let inventory: any = [];
let updatedQuery = totalInvNoRn;

View File

@@ -22,13 +22,17 @@ app.openapi(
async (c) => {
//const body = await c.req.json();
// make sure we have a vaid user being accessed thats really logged in
const includePlantToken: any = c.req.queries();
apiHit(c, { endpoint: "/getarticles" });
try {
return c.json(
{
success: true,
message: "Current active Articles",
data: await getActiveAv(),
data: await getActiveAv(
includePlantToken["includePlantToken"] ? true : false
),
},
200
);