test(datamart): more data mart work

This commit is contained in:
2025-12-31 15:14:54 -06:00
parent 04fe1f1bfe
commit 4e6d35bc67
4 changed files with 51 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
/** /**
* each endpoint will be something like * each endpoint will be something like
* /api/datamart/{name}?{options} * /api/datamart/{name}?{criteria}
* *
* when getting the current queries we will need to map through the available queries we currently have and send back. * when getting the current queries we will need to map through the available queries we currently have and send back.
* example * example
@@ -8,7 +8,7 @@
* "name": "getopenorders", * "name": "getopenorders",
* "endpoint": "/api/datamart/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", * "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" * "options": "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 * 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

View File

@@ -1,18 +1,54 @@
import { Router } from "express"; import { Router } from "express";
import z from "zod";
import type { NewDatamart } from "../db/schema/datamart.schema.js";
import { apiReturn } from "../utils/returnHelper.utils.js"; import { apiReturn } from "../utils/returnHelper.utils.js";
const r = Router(); const r = Router();
r.post("/add", async (_, res) => { const newQuery = z.object({
apiReturn(res, { name: z.string().min(5),
success: true, description: z.string().min(30),
level: "info", query: z.string().min(10),
module: "routes", options: z
subModule: "prodSql", .string()
message: "connect.message", .describe("This should be a set of keys separated by a comma")
data: [{ connect: "" }], .optional(),
status: 200, });
});
r.post("/add", async (req, res) => {
try {
const v = newQuery.parse(req.body);
const query: NewDatamart = { ...v };
} 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: "routes",
subModule: "auth",
message: "Validation failed",
data: [flattened.fieldErrors],
status: 400, //connect.success ? 200 : 400,
});
}
return apiReturn(res, {
success: true,
level: "info",
module: "routes",
subModule: "prodSql",
message: "connect.message",
data: [{ connect: "" }],
status: 200,
});
}
}); });
export default r; export default r;

View File

@@ -14,7 +14,7 @@ export const datamart = pgTable("datamart", {
name: text("name"), name: text("name"),
description: text("description").notNull(), description: text("description").notNull(),
query: text("query"), query: text("query"),
version: integer("version").notNull(), version: integer("version").default(1).notNull(),
active: boolean("active").default(true), active: boolean("active").default(true),
options: text("checked").default(""), options: text("checked").default(""),
add_date: timestamp("add_date").defaultNow(), add_date: timestamp("add_date").defaultNow(),

View File

@@ -11,7 +11,8 @@ interface Data {
| "prodSql" | "prodSql"
| "query" | "query"
| "sendmail" | "sendmail"
| "auth"; | "auth"
| "datamart";
level: "info" | "error" | "debug" | "fatal"; level: "info" | "error" | "debug" | "fatal";
message: string; message: string;
data?: unknown[]; data?: unknown[];