|
|
@ -135,6 +135,11 @@ class Xapi { |
|
|
|
.get(this.asyncMiddleware(this.list.bind(this))); |
|
|
|
.get(this.asyncMiddleware(this.list.bind(this))); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'findOne': |
|
|
|
|
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
|
|
|
|
.get(this.asyncMiddleware(this.findOne.bind(this))); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'create': |
|
|
|
case 'create': |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
.post(this.asyncMiddleware(this.create.bind(this))); |
|
|
|
.post(this.asyncMiddleware(this.create.bind(this))); |
|
|
@ -211,12 +216,11 @@ class Xapi { |
|
|
|
|
|
|
|
|
|
|
|
console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '); |
|
|
|
console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '); |
|
|
|
console.log(' '); |
|
|
|
console.log(' '); |
|
|
|
console.log(' Database : %s',this.config.database); |
|
|
|
console.log(' Database : %s', this.config.database); |
|
|
|
console.log(' Number of resources : %s',stat.tables); |
|
|
|
console.log(' Number of resources : %s', stat.tables); |
|
|
|
console.log(' '); |
|
|
|
console.log(' '); |
|
|
|
console.log(' REST APIs Generated : %s'.green.bold,stat.apis ); |
|
|
|
console.log(' REST APIs Generated : %s'.green.bold, stat.apis); |
|
|
|
console.log(' '); |
|
|
|
console.log(' '); |
|
|
|
|
|
|
|
|
|
|
|
return stat |
|
|
|
return stat |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -233,7 +237,16 @@ class Xapi { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
prepareListQuery(req, res, queryParamsObj, nested = false) { |
|
|
|
/** |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param req |
|
|
|
|
|
|
|
* @param res |
|
|
|
|
|
|
|
* @param queryParamsObj : {query, params} |
|
|
|
|
|
|
|
* @param listType : 0:list, 1:nested, 2:findOne |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Updates query, params for query of type listType |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
prepareListQuery(req, res, queryParamsObj, listType = 0) { |
|
|
|
|
|
|
|
|
|
|
|
queryParamsObj.query = 'select '; |
|
|
|
queryParamsObj.query = 'select '; |
|
|
|
queryParamsObj.params = []; |
|
|
|
queryParamsObj.params = []; |
|
|
@ -248,7 +261,7 @@ class Xapi { |
|
|
|
/**************** add tableName ****************/ |
|
|
|
/**************** add tableName ****************/ |
|
|
|
queryParamsObj.query += ' from ?? '; |
|
|
|
queryParamsObj.query += ' from ?? '; |
|
|
|
|
|
|
|
|
|
|
|
if (nested) { |
|
|
|
if (listType === 1) { |
|
|
|
|
|
|
|
|
|
|
|
req.app.locals._tableName = req.app.locals._childTable; |
|
|
|
req.app.locals._tableName = req.app.locals._childTable; |
|
|
|
|
|
|
|
|
|
|
@ -289,8 +302,12 @@ class Xapi { |
|
|
|
this.mysql.getOrderByClause(req.query, req.app.locals._tableName, queryParamsObj); |
|
|
|
this.mysql.getOrderByClause(req.query, req.app.locals._tableName, queryParamsObj); |
|
|
|
|
|
|
|
|
|
|
|
/**************** add limit clause ****************/ |
|
|
|
/**************** add limit clause ****************/ |
|
|
|
|
|
|
|
if (listType === 2) { |
|
|
|
|
|
|
|
queryParamsObj.query += ' limit 1 ' |
|
|
|
|
|
|
|
} else { |
|
|
|
queryParamsObj.query += ' limit ?,? ' |
|
|
|
queryParamsObj.query += ' limit ?,? ' |
|
|
|
queryParamsObj.params = queryParamsObj.params.concat(this.mysql.getLimitClause(req.query)); |
|
|
|
queryParamsObj.params = queryParamsObj.params.concat(this.mysql.getLimitClause(req.query)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//console.log(queryParamsObj.query, queryParamsObj.params);
|
|
|
|
//console.log(queryParamsObj.query, queryParamsObj.params);
|
|
|
|
|
|
|
|
|
|
|
@ -302,7 +319,7 @@ class Xapi { |
|
|
|
queryParamsObj.query = '' |
|
|
|
queryParamsObj.query = '' |
|
|
|
queryParamsObj.params = [] |
|
|
|
queryParamsObj.params = [] |
|
|
|
|
|
|
|
|
|
|
|
this.prepareListQuery(req, res, queryParamsObj, false); |
|
|
|
this.prepareListQuery(req, res, queryParamsObj, 0); |
|
|
|
|
|
|
|
|
|
|
|
let results = await this.mysql.exec(queryParamsObj.query, queryParamsObj.params); |
|
|
|
let results = await this.mysql.exec(queryParamsObj.query, queryParamsObj.params); |
|
|
|
res.status(200).json(results); |
|
|
|
res.status(200).json(results); |
|
|
@ -315,7 +332,20 @@ class Xapi { |
|
|
|
queryParamsObj.query = ''; |
|
|
|
queryParamsObj.query = ''; |
|
|
|
queryParamsObj.params = []; |
|
|
|
queryParamsObj.params = []; |
|
|
|
|
|
|
|
|
|
|
|
this.prepareListQuery(req, res, queryParamsObj, true) |
|
|
|
this.prepareListQuery(req, res, queryParamsObj, 1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let results = await this.mysql.exec(queryParamsObj.query, queryParamsObj.params); |
|
|
|
|
|
|
|
res.status(200).json(results); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async findOne(req, res) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let queryParamsObj = {} |
|
|
|
|
|
|
|
queryParamsObj.query = '' |
|
|
|
|
|
|
|
queryParamsObj.params = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.prepareListQuery(req, res, queryParamsObj, 2); |
|
|
|
|
|
|
|
|
|
|
|
let results = await this.mysql.exec(queryParamsObj.query, queryParamsObj.params); |
|
|
|
let results = await this.mysql.exec(queryParamsObj.query, queryParamsObj.params); |
|
|
|
res.status(200).json(results); |
|
|
|
res.status(200).json(results); |
|
|
@ -488,13 +518,13 @@ class Xapi { |
|
|
|
queryParamsObj.params = []; |
|
|
|
queryParamsObj.params = []; |
|
|
|
|
|
|
|
|
|
|
|
/**************** add columns and group by columns ****************/ |
|
|
|
/**************** add columns and group by columns ****************/ |
|
|
|
this.mysql.getColumnsForSelectStmt(req.app.locals._tableName,req.query,queryParamsObj) |
|
|
|
this.mysql.getColumnsForSelectStmt(req.app.locals._tableName, req.query, queryParamsObj) |
|
|
|
|
|
|
|
|
|
|
|
queryParamsObj.query += ',count(*) as _count from ?? group by '; |
|
|
|
queryParamsObj.query += ',count(*) as _count from ?? group by '; |
|
|
|
let tableName = req.app.locals._tableName; |
|
|
|
let tableName = req.app.locals._tableName; |
|
|
|
queryParamsObj.params.push(tableName); |
|
|
|
queryParamsObj.params.push(tableName); |
|
|
|
|
|
|
|
|
|
|
|
this.mysql.getColumnsForSelectStmt(req.app.locals._tableName,req.query,queryParamsObj) |
|
|
|
this.mysql.getColumnsForSelectStmt(req.app.locals._tableName, req.query, queryParamsObj) |
|
|
|
|
|
|
|
|
|
|
|
if (!req.query._sort) { |
|
|
|
if (!req.query._sort) { |
|
|
|
req.query._sort = {} |
|
|
|
req.query._sort = {} |
|
|
|