|
|
|
@ -135,6 +135,11 @@ class Xapi {
|
|
|
|
|
.get(this.asyncMiddleware(this.list.bind(this))); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'findOne': |
|
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
|
.get(this.asyncMiddleware(this.findOne.bind(this))); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'create': |
|
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
|
.post(this.asyncMiddleware(this.create.bind(this))); |
|
|
|
@ -216,7 +221,6 @@ class Xapi {
|
|
|
|
|
console.log(' '); |
|
|
|
|
console.log(' REST APIs Generated : %s'.green.bold, stat.apis); |
|
|
|
|
console.log(' '); |
|
|
|
|
|
|
|
|
|
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.params = []; |
|
|
|
@ -248,7 +261,7 @@ class Xapi {
|
|
|
|
|
/**************** add tableName ****************/ |
|
|
|
|
queryParamsObj.query += ' from ?? '; |
|
|
|
|
|
|
|
|
|
if (nested) { |
|
|
|
|
if (listType === 1) { |
|
|
|
|
|
|
|
|
|
req.app.locals._tableName = req.app.locals._childTable; |
|
|
|
|
|
|
|
|
@ -289,8 +302,12 @@ class Xapi {
|
|
|
|
|
this.mysql.getOrderByClause(req.query, req.app.locals._tableName, queryParamsObj); |
|
|
|
|
|
|
|
|
|
/**************** add limit clause ****************/ |
|
|
|
|
if (listType === 2) { |
|
|
|
|
queryParamsObj.query += ' limit 1 ' |
|
|
|
|
} else { |
|
|
|
|
queryParamsObj.query += ' limit ?,? ' |
|
|
|
|
queryParamsObj.params = queryParamsObj.params.concat(this.mysql.getLimitClause(req.query)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//console.log(queryParamsObj.query, queryParamsObj.params);
|
|
|
|
|
|
|
|
|
@ -302,7 +319,7 @@ class Xapi {
|
|
|
|
|
queryParamsObj.query = '' |
|
|
|
|
queryParamsObj.params = [] |
|
|
|
|
|
|
|
|
|
this.prepareListQuery(req, res, queryParamsObj, false); |
|
|
|
|
this.prepareListQuery(req, res, queryParamsObj, 0); |
|
|
|
|
|
|
|
|
|
let results = await this.mysql.exec(queryParamsObj.query, queryParamsObj.params); |
|
|
|
|
res.status(200).json(results); |
|
|
|
@ -315,7 +332,20 @@ class Xapi {
|
|
|
|
|
queryParamsObj.query = ''; |
|
|
|
|
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); |
|
|
|
|
res.status(200).json(results); |
|
|
|
|