error pass and select fix
This commit is contained in:
parent
7497787ae4
commit
ac5a7e7427
2 changed files with 28 additions and 9 deletions
|
@ -37,6 +37,7 @@ export async function executeQuery(req: Request, res: Response): Promise<any> {
|
|||
let count = parseInt((req.query.count as string) ?? "25");
|
||||
const query = req.body.query;
|
||||
|
||||
try {
|
||||
let [rows, total] = await DynamicQueryBuilder.buildQuery(query, offset, count).getManyAndCount();
|
||||
|
||||
res.json({
|
||||
|
@ -45,4 +46,11 @@ export async function executeQuery(req: Request, res: Response): Promise<any> {
|
|||
offset: offset,
|
||||
count: count,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).send({
|
||||
json: error.sql,
|
||||
code: error.code,
|
||||
msg: error.sqlMessage,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,11 +67,22 @@ export default abstract class DynamicQueryBuilder {
|
|||
depth: number = 0
|
||||
): void {
|
||||
const alias = queryObject.table + "_" + depth;
|
||||
let firstSelect = true;
|
||||
let selects: Array<string> = [];
|
||||
|
||||
if (queryObject.select == "*") {
|
||||
query.addSelect(`${alias}.*`);
|
||||
let meta = this.getTableMeta(queryObject.table);
|
||||
let relCols = meta.relations.map((r) => r.column);
|
||||
selects = meta.columns.map((c) => c.column).filter((c) => !relCols.includes(c));
|
||||
} else {
|
||||
selects = queryObject.select;
|
||||
}
|
||||
|
||||
for (const select of selects) {
|
||||
if (firstSelect) {
|
||||
query.select(`${alias}.${select}`);
|
||||
firstSelect = false;
|
||||
} else {
|
||||
for (const select of queryObject.select) {
|
||||
query.addSelect(`${alias}.${select}`);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue