enhance: add endpoint to fetch query data by query store id
This commit is contained in:
parent
fdf67d4763
commit
16f6846d89
2 changed files with 31 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
import { Request, Response } from "express";
|
||||
import DynamicQueryBuilder from "../../../helpers/dynamicQueryBuilder";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import QueryStoreService from "../../../service/configuration/queryStoreService";
|
||||
|
||||
/**
|
||||
* @description get all table metas
|
||||
|
@ -43,3 +44,23 @@ export async function executeQuery(req: Request, res: Response): Promise<any> {
|
|||
|
||||
res.json(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description execute Query by StoreId
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function executeQueryByStoreId(req: Request, res: Response): Promise<any> {
|
||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
||||
let count = parseInt((req.query.count as string) ?? "25");
|
||||
let noLimit = req.query.noLimit === "true";
|
||||
const storeId = req.params.storeId;
|
||||
|
||||
let queryStore = await QueryStoreService.getById(storeId);
|
||||
let query = queryStore.query.startsWith("{") ? JSON.parse(queryStore.query) : queryStore.query;
|
||||
|
||||
let result = await DynamicQueryBuilder.executeQuery({ query, offset, count, noLimit });
|
||||
|
||||
res.json(result);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import express, { Request, Response } from "express";
|
||||
import { executeQuery, getAllTableMeta, getTableMetaByTablename } from "../../../controller/admin/club/queryBuilderController";
|
||||
import {
|
||||
executeQuery,
|
||||
executeQueryByStoreId,
|
||||
getAllTableMeta,
|
||||
getTableMetaByTablename,
|
||||
} from "../../../controller/admin/club/queryBuilderController";
|
||||
|
||||
var router = express.Router({ mergeParams: true });
|
||||
|
||||
|
@ -15,4 +20,8 @@ router.post("/query", async (req: Request, res: Response) => {
|
|||
await executeQuery(req, res);
|
||||
});
|
||||
|
||||
router.post("/query/:storeId", async (req: Request, res: Response) => {
|
||||
await executeQueryByStoreId(req, res);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
|
Loading…
Add table
Reference in a new issue