test(datamart): more work on datamart setup

This commit is contained in:
2026-01-03 10:48:56 -06:00
parent 404974dde0
commit c06a52a4ac
4 changed files with 62 additions and 5 deletions

32
.env-example Normal file
View File

@@ -0,0 +1,32 @@
# Server
PORT=3000
URL=http://localhost:3000
# authentication
BETTER_AUTH_SECRET=""
RESET_EXPIRY_SECONDS=3600
# logging
LOG_LEVEL=debug
# prodServer
PROD_SERVER=usmcd1vms036
PROD_PLANT_TOKEN=test3
PROD_USER=alplaprod
PROD_PASSWORD=password
# postgres connection
DATABASE_HOST=localhost
DATABASE_PORT=5433
DATABASE_USER=user
DATABASE_PASSWORD=password
DATABASE_DB=lst_dev
# how is the app running server or client when in client mode you must provide the server
APP_RUNNING_IN=server
SERVER_NAME=localhost
#dev stuff
GITEA_TOKEN=""
EMAIL_USER=""
EMAIL_PASSWORD=""

View File

@@ -1,7 +1,32 @@
import { eq } from "drizzle-orm";
import type { Express } from "express";
import { db } from "../db/db.controller.js";
import { datamart } from "../db/schema/datamart.schema.js";
import { apiReturn } from "../utils/returnHelper.utils.js";
import addQuery from "./datamartAdd.route.js";
import runQuery from "./getDatamart.route.js";
export const setupDatamartRoutes = (baseUrl: string, app: Express) => {
//setup all the routes
app.use(`${baseUrl}/api/datamart`, runQuery);
app.use(`${baseUrl}/api/datamart`, addQuery);
// just sending a get on datamart will return all the queries that we can call.
app.get(`${baseUrl}/api/datamart`, async (_, res) => {
const queries = await db
.select()
.from(datamart)
.where(eq(datamart.active, true));
return apiReturn(res, {
success: true,
level: "info",
module: "datamart",
subModule: "query",
message: "All active queries we can run",
data: queries,
status: 200,
});
});
};

View File

@@ -15,7 +15,7 @@ const newQuery = z.object({
.optional(),
});
r.post("/add", async (req, res) => {
r.post("/", async (req, res) => {
try {
const v = newQuery.parse(req.body);
@@ -36,7 +36,7 @@ r.post("/add", async (req, res) => {
module: "routes",
subModule: "auth",
message: "Validation failed",
data: [flattened.fieldErrors],
data: [flattened],
status: 400, //connect.success ? 200 : 400,
});
}
@@ -46,8 +46,8 @@ r.post("/add", async (req, res) => {
level: "error",
module: "routes",
subModule: "datamart",
message: "connect.message",
data: [{ connect: "" }],
message: "There was an error creating the new query",
data: [err],
status: 200,
});
}

View File

@@ -11,7 +11,7 @@ r.get("/:name", async (req, res) => {
).toString();
const dataRan = await runDatamartQuery({ name, criteria });
apiReturn(res, {
return apiReturn(res, {
success: dataRan.success,
level: "info",
module: "datamart",