test(datamart): more data mart work
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 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.
|
||||
* example
|
||||
@@ -8,7 +8,7 @@
|
||||
* "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"
|
||||
* "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
|
||||
|
||||
@@ -1,18 +1,54 @@
|
||||
import { Router } from "express";
|
||||
import z from "zod";
|
||||
import type { NewDatamart } from "../db/schema/datamart.schema.js";
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
|
||||
const r = Router();
|
||||
|
||||
r.post("/add", async (_, res) => {
|
||||
apiReturn(res, {
|
||||
success: true,
|
||||
level: "info",
|
||||
module: "routes",
|
||||
subModule: "prodSql",
|
||||
message: "connect.message",
|
||||
data: [{ connect: "" }],
|
||||
status: 200,
|
||||
});
|
||||
const newQuery = z.object({
|
||||
name: z.string().min(5),
|
||||
description: z.string().min(30),
|
||||
query: z.string().min(10),
|
||||
options: z
|
||||
.string()
|
||||
.describe("This should be a set of keys separated by a comma")
|
||||
.optional(),
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
@@ -14,7 +14,7 @@ export const datamart = pgTable("datamart", {
|
||||
name: text("name"),
|
||||
description: text("description").notNull(),
|
||||
query: text("query"),
|
||||
version: integer("version").notNull(),
|
||||
version: integer("version").default(1).notNull(),
|
||||
active: boolean("active").default(true),
|
||||
options: text("checked").default(""),
|
||||
add_date: timestamp("add_date").defaultNow(),
|
||||
|
||||
@@ -11,7 +11,8 @@ interface Data {
|
||||
| "prodSql"
|
||||
| "query"
|
||||
| "sendmail"
|
||||
| "auth";
|
||||
| "auth"
|
||||
| "datamart";
|
||||
level: "info" | "error" | "debug" | "fatal";
|
||||
message: string;
|
||||
data?: unknown[];
|
||||
|
||||
Reference in New Issue
Block a user