feat(datamart): active article moved over to the new version
This commit is contained in:
89
app/src/internal/datamart/routes/getActiveAv.ts
Normal file
89
app/src/internal/datamart/routes/getActiveAv.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Router, type Request, type Response } from "express";
|
||||
import { prodQuery } from "../../../pkg/prodSql/prodQuery.js";
|
||||
import { tryCatch } from "../../../pkg/utils/tryCatch.js";
|
||||
import { db } from "../../../pkg/db/db.js";
|
||||
import { settings } from "../../../pkg/db/schema/settings.js";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { activeArticle } from "../../../pkg/prodSql/querys/datamart/article.js";
|
||||
|
||||
type Articles = {
|
||||
article: string
|
||||
description: string
|
||||
articleType: string
|
||||
pricePoint:string
|
||||
salesPrice:string
|
||||
typeOfMaterial:string
|
||||
articleIdType:string
|
||||
articleWeight:string
|
||||
idAddress:string
|
||||
addressDescription:string
|
||||
addressType:string
|
||||
profitCenter:String
|
||||
fg: string
|
||||
num_of_cycles:string
|
||||
costsCenterId:string
|
||||
costCenterDescription:string
|
||||
customerArticleNumber:string
|
||||
customerArticleDescription:String
|
||||
cycleTime:string
|
||||
salesAgreement:string
|
||||
productFamily:string
|
||||
uom:string
|
||||
}
|
||||
|
||||
|
||||
const router = Router();
|
||||
|
||||
// GET /health
|
||||
router.get("/", async (req: Request, res: Response) => {
|
||||
|
||||
const includePlantToken = req.params.includePlantToken
|
||||
|
||||
let articles:Articles[] = [];
|
||||
try {
|
||||
const res = await prodQuery(activeArticle, "Get active articles");
|
||||
articles = res?.data;
|
||||
}
|
||||
catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
message:"Error getting articles",
|
||||
error: error
|
||||
};
|
||||
}
|
||||
if (includePlantToken) {
|
||||
const { data, error } = await tryCatch(db.select().from(settings).where(eq(settings.name, "plantToken")))
|
||||
if (error) {
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message:"Error getting settings",
|
||||
error: error
|
||||
};
|
||||
}
|
||||
// return articles.map((n) => {
|
||||
// return {
|
||||
// success: true,
|
||||
// message: "Active articles including plant token",
|
||||
// data:{ plantToken: data[0].value, ...n }};
|
||||
// });
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Active articles including plant token",
|
||||
data: articles.map((n) => {
|
||||
return { plantToken: data[0].value, ...n }
|
||||
})
|
||||
}
|
||||
}
|
||||
else {
|
||||
return {
|
||||
success: true,
|
||||
message: "Active articles including plant token",
|
||||
data:articles};
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
export default router;
|
||||
10
app/src/internal/datamart/routes/routes.ts
Normal file
10
app/src/internal/datamart/routes/routes.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { Express, Request, Response } from "express";
|
||||
|
||||
//datamart Routes
|
||||
import getActiveAv from './getActiveAv.js'
|
||||
export const setupDataMartRoutes = (app: Express, basePath: string) => {
|
||||
const route = basePath + "/api/datamart"
|
||||
app.use(route + '/activeArticle', getActiveAv);
|
||||
//app.use(basePath + "/api/user/me", requireAuth(), me);
|
||||
|
||||
};
|
||||
@@ -5,6 +5,7 @@ import { setupForkliftRoutes } from "../forklifts/routes/routes.js";
|
||||
import { setupLogisticsRoutes } from "../logistics/routes.js";
|
||||
import { setupSystemRoutes } from "../system/routes.js";
|
||||
import { setupMobileRoutes } from "../mobile/route.js";
|
||||
import { setupDataMartRoutes } from "../datamart/routes/routes.js";
|
||||
|
||||
export const setupRoutes = (app: Express, basePath: string) => {
|
||||
// all routes
|
||||
@@ -14,6 +15,7 @@ export const setupRoutes = (app: Express, basePath: string) => {
|
||||
setupLogisticsRoutes(app, basePath);
|
||||
setupForkliftRoutes(app, basePath);
|
||||
setupMobileRoutes(app, basePath);
|
||||
setupDataMartRoutes(app, basePath)
|
||||
|
||||
// always try to go to the app weather we are in dev or in production.
|
||||
app.get(basePath + "/", (req: Request, res: Response) => {
|
||||
|
||||
Reference in New Issue
Block a user