/** * 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, }); };