feat(datamart): intial foundation of the datamart setup
this will allow for faster datamart addtions and updates
This commit is contained in:
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -52,6 +52,7 @@
|
|||||||
"alpla",
|
"alpla",
|
||||||
"alplamart",
|
"alplamart",
|
||||||
"alplaprod",
|
"alplaprod",
|
||||||
|
"Datamart",
|
||||||
"intiallally",
|
"intiallally",
|
||||||
"ppoo",
|
"ppoo",
|
||||||
"prodlabels"
|
"prodlabels"
|
||||||
|
|||||||
51
backend/src/datamart/datamart.controller.ts
Normal file
51
backend/src/datamart/datamart.controller.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
* each endpoint will be something like
|
||||||
|
* /api/datamart/{name}?{options}
|
||||||
|
*
|
||||||
|
* when getting the current queries we will need to map through the available queries we currently have and send back.
|
||||||
|
* example
|
||||||
|
*{
|
||||||
|
* "name": "getopenorders",
|
||||||
|
* "endpoint": "/api/datamart/getopenorders",
|
||||||
|
* "description": "Returns open orders based on day count sent over, sDay 15 days in the past eDay 5 days in the future, can be left empty for this default days",
|
||||||
|
* "criteria": "sDay,eDay"
|
||||||
|
* },
|
||||||
|
*
|
||||||
|
* when a criteria is password over we will handle it by counting how many were passed up to 3 then deal with each one respectively
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { returnFunc } from "../utils/returnHelper.utils.js";
|
||||||
|
|
||||||
|
type Data = {
|
||||||
|
name: string;
|
||||||
|
criteria: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const runDatamartQuery = async (data: Data) => {
|
||||||
|
// search the query db for the query by name
|
||||||
|
const dummyquery = {
|
||||||
|
name: "something",
|
||||||
|
query: "select * from tableA where start=[start] and end=[end]",
|
||||||
|
};
|
||||||
|
|
||||||
|
// create the query with no changed just to have it here
|
||||||
|
let datamartQuery = dummyquery.query;
|
||||||
|
// split the criteria by "," then and then update the query
|
||||||
|
if (data.criteria) {
|
||||||
|
const params = new URLSearchParams(data.criteria);
|
||||||
|
|
||||||
|
for (const [key, value] of params.entries()) {
|
||||||
|
datamartQuery = datamartQuery.replaceAll(`[${key}]`, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnFunc({
|
||||||
|
success: true,
|
||||||
|
level: "info",
|
||||||
|
module: "datamart",
|
||||||
|
subModule: "query",
|
||||||
|
message: `Data for: ${data.name}`,
|
||||||
|
data: [{ data: datamartQuery }],
|
||||||
|
notify: false,
|
||||||
|
});
|
||||||
|
};
|
||||||
13
backend/src/datamart/datamart.routes.ts
Normal file
13
backend/src/datamart/datamart.routes.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import type { Express } from "express";
|
||||||
|
import runQuery from "./getDatamart.route.js";
|
||||||
|
export const setupDatamartRoutes = (baseUrl: string, app: Express) => {
|
||||||
|
//setup all the routes
|
||||||
|
|
||||||
|
app.use(`${baseUrl}/api/datamart`, runQuery);
|
||||||
|
|
||||||
|
app.all("*foo", (_, res) => {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "You have encountered a datamart route that dose not exist",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
22
backend/src/datamart/datamartSync.controller.ts
Normal file
22
backend/src/datamart/datamartSync.controller.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* If we are running in client mode we want to periodically check the SERVER_NAME for new/updates queries
|
||||||
|
* this will be on a cronner job, we will check 2 times a day for new data, we will also have a route we can trigger to check this manually incase we have
|
||||||
|
* queries we make for one plant but will eventually go to all plants.
|
||||||
|
* in client mode we will not be able to add, update, or delete
|
||||||
|
*
|
||||||
|
* if we are running on server mode we will provide all queries.
|
||||||
|
* allow for new queries to be added
|
||||||
|
* allow for queries to be updated by id
|
||||||
|
* table will be
|
||||||
|
* id
|
||||||
|
* name
|
||||||
|
* description
|
||||||
|
* query
|
||||||
|
* version
|
||||||
|
* active
|
||||||
|
* options (string ie start,end)
|
||||||
|
* add_date
|
||||||
|
* add_user
|
||||||
|
* upd_date
|
||||||
|
* upd_user
|
||||||
|
*/
|
||||||
25
backend/src/datamart/getDatamart.route.ts
Normal file
25
backend/src/datamart/getDatamart.route.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { Router } from "express";
|
||||||
|
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||||
|
import { runDatamartQuery } from "./datamart.controller.js";
|
||||||
|
|
||||||
|
const r = Router();
|
||||||
|
|
||||||
|
r.get("/:name", async (req, res) => {
|
||||||
|
const { name } = req.params;
|
||||||
|
const criteria = new URLSearchParams(
|
||||||
|
req.query as Record<string, string>,
|
||||||
|
).toString();
|
||||||
|
|
||||||
|
const dataRan = await runDatamartQuery({ name, criteria });
|
||||||
|
apiReturn(res, {
|
||||||
|
success: dataRan.success,
|
||||||
|
level: "info",
|
||||||
|
module: "datamart",
|
||||||
|
subModule: "query",
|
||||||
|
message: dataRan.message,
|
||||||
|
data: dataRan.data,
|
||||||
|
status: 200,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export default r;
|
||||||
6
backend/src/db/dbBackup.contoller.ts
Normal file
6
backend/src/db/dbBackup.contoller.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* while in client mode we will be connected directly to the postgres and do a nightly backup.
|
||||||
|
* we will only keep tables relevant, like silo data, inv history, manualPrinting, notifications, printerData,prodlabels, quality request, rfid tags, roles, serverData,...etc
|
||||||
|
* keeping only the last 7 backups
|
||||||
|
*
|
||||||
|
*/
|
||||||
@@ -2,6 +2,7 @@ import type { Express } from "express";
|
|||||||
|
|
||||||
// import the routes and route setups
|
// import the routes and route setups
|
||||||
import { setupApiDocsRoutes } from "./configs/scaler.config.js";
|
import { setupApiDocsRoutes } from "./configs/scaler.config.js";
|
||||||
|
import { setupDatamartRoutes } from "./datamart/datamart.routes.js";
|
||||||
import { setupProdSqlRoutes } from "./prodSql/prodSql.routes.js";
|
import { setupProdSqlRoutes } from "./prodSql/prodSql.routes.js";
|
||||||
import stats from "./system/stats.route.js";
|
import stats from "./system/stats.route.js";
|
||||||
|
|
||||||
@@ -9,6 +10,7 @@ export const setupRoutes = (baseUrl: string, app: Express) => {
|
|||||||
//setup all the routes
|
//setup all the routes
|
||||||
setupApiDocsRoutes(baseUrl, app);
|
setupApiDocsRoutes(baseUrl, app);
|
||||||
setupProdSqlRoutes(baseUrl, app);
|
setupProdSqlRoutes(baseUrl, app);
|
||||||
|
setupDatamartRoutes(baseUrl, app);
|
||||||
|
|
||||||
app.use(`${baseUrl}/api/stats`, stats);
|
app.use(`${baseUrl}/api/stats`, stats);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { createLogger } from "../logger/logger.controller.js";
|
|||||||
|
|
||||||
interface Data {
|
interface Data {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
module: "system" | "ocp" | "routes";
|
module: "system" | "ocp" | "routes" | "datamart";
|
||||||
subModule: "db" | "labeling" | "printer" | "prodSql";
|
subModule: "db" | "labeling" | "printer" | "prodSql" | "query";
|
||||||
level: "info" | "error" | "debug" | "fatal";
|
level: "info" | "error" | "debug" | "fatal";
|
||||||
message: string;
|
message: string;
|
||||||
data?: unknown[];
|
data?: unknown[];
|
||||||
|
|||||||
Reference in New Issue
Block a user