|
|
@ -69,10 +69,13 @@ class Xapi { |
|
|
|
|
|
|
|
|
|
|
|
if (err && err.code) |
|
|
|
if (err && err.code) |
|
|
|
res.status(400).json({error: err}); |
|
|
|
res.status(400).json({error: err}); |
|
|
|
else |
|
|
|
else if (err && err.message) |
|
|
|
res.status(500).json({error: 'Internal server error : ' + err.message}); |
|
|
|
res.status(500).json({error: 'Internal server error : ' + err.message}); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
res.status(500).json({error: 'Internal server error : ' + err}); |
|
|
|
|
|
|
|
|
|
|
|
next(err); |
|
|
|
next(err); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
asyncMiddleware(fn) { |
|
|
|
asyncMiddleware(fn) { |
|
|
@ -416,6 +419,7 @@ class Xapi { |
|
|
|
|
|
|
|
|
|
|
|
async groupBy(req, res) { |
|
|
|
async groupBy(req, res) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (req.query && req.query._fields) { |
|
|
|
let query = 'select ' + req.query._fields + ',count(*) as count from ?? group by ' + req.query._fields; |
|
|
|
let query = 'select ' + req.query._fields + ',count(*) as count from ?? group by ' + req.query._fields; |
|
|
|
let params = []; |
|
|
|
let params = []; |
|
|
|
let tableName = req.app.locals._tableName; |
|
|
|
let tableName = req.app.locals._tableName; |
|
|
@ -432,11 +436,17 @@ class Xapi { |
|
|
|
var results = await this.mysql.exec(query, params); |
|
|
|
var results = await this.mysql.exec(query, params); |
|
|
|
|
|
|
|
|
|
|
|
res.status(200).json(results); |
|
|
|
res.status(200).json(results); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
res.status(400).json({message: 'Missing _fields query params eg: /api/tableName/groupby?_fields=column1'}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async aggregate(req, res) { |
|
|
|
async aggregate(req, res) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (req.query && req.query._fields) { |
|
|
|
let tableName = req.app.locals._tableName; |
|
|
|
let tableName = req.app.locals._tableName; |
|
|
|
let query = 'select ' |
|
|
|
let query = 'select ' |
|
|
|
let params = [] |
|
|
|
let params = [] |
|
|
@ -467,6 +477,9 @@ class Xapi { |
|
|
|
var results = await this.mysql.exec(query, params); |
|
|
|
var results = await this.mysql.exec(query, params); |
|
|
|
|
|
|
|
|
|
|
|
res.status(200).json(results); |
|
|
|
res.status(200).json(results); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
res.status(400).json({message:'Missing _fields in query params eg: /api/tableName/groupby?_fields=numericColumn1'}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|