From 2d218b33bd7a6f1a821bbf0e991048fa68e8b4c7 Mon Sep 17 00:00:00 2001 From: oof1lab Date: Mon, 6 Nov 2017 18:10:52 +0000 Subject: [PATCH] refactor : turning group fields as params --- lib/xapi.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/xapi.js b/lib/xapi.js index aef5cdfbcd..d6c14b9372 100644 --- a/lib/xapi.js +++ b/lib/xapi.js @@ -482,21 +482,27 @@ class Xapi { if (req.query && req.query._fields) { let queryParamsObj = {} - queryParamsObj.query = ''; + queryParamsObj.query = 'select '; queryParamsObj.params = []; - queryParamsObj.query = 'select ' + req.query._fields + ',count(*) as _count from ?? group by ' + req.query._fields; + /**************** add columns and group by columns ****************/ + this.mysql.getColumnsForSelectStmt(req.app.locals._tableName,req.query,queryParamsObj) + + queryParamsObj.query += ',count(*) as _count from ?? group by '; let tableName = req.app.locals._tableName; queryParamsObj.params.push(tableName); + this.mysql.getColumnsForSelectStmt(req.app.locals._tableName,req.query,queryParamsObj) + if (!req.query._sort) { req.query._sort = {} req.query._sort = '-_count' } - /**************** where clause ****************/ + /**************** add having clause ****************/ this.mysql.getHavingClause(req.query._having, req.app.locals._tableName, queryParamsObj, ' having '); + /**************** add orderby clause ****************/ this.mysql.getOrderByClause(req.query, tableName, queryParamsObj); //console.log(queryParamsObj.query, queryParamsObj.params);