|
|
@ -112,7 +112,6 @@ class Xapi { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************** START : setup routes for each table ****************/ |
|
|
|
/**************** START : setup routes for each table ****************/ |
|
|
|
|
|
|
|
|
|
|
|
let resources = []; |
|
|
|
let resources = []; |
|
|
|
resources = this.mysql.getSchemaRoutes(true, '/api/'); |
|
|
|
resources = this.mysql.getSchemaRoutes(true, '/api/'); |
|
|
|
|
|
|
|
|
|
|
@ -150,6 +149,11 @@ class Xapi { |
|
|
|
.get(this.asyncMiddleware(this.read.bind(this))); |
|
|
|
.get(this.asyncMiddleware(this.read.bind(this))); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'patch': |
|
|
|
|
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
|
|
|
|
.patch(this.asyncMiddleware(this.patch.bind(this))); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'update': |
|
|
|
case 'update': |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
.put(this.asyncMiddleware(this.update.bind(this))); |
|
|
|
.put(this.asyncMiddleware(this.update.bind(this))); |
|
|
@ -246,6 +250,7 @@ class Xapi { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* |
|
|
|
* |
|
|
|
* @param req |
|
|
|
* @param req |
|
|
@ -412,8 +417,22 @@ class Xapi { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async update(req, res) { |
|
|
|
async update(req, res) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let query = 'REPLACE INTO ?? SET ?'; |
|
|
|
|
|
|
|
let params = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params.push(req.app.locals._tableName); |
|
|
|
|
|
|
|
params.push(req.body); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var results = await this.mysql.exec(query, params); |
|
|
|
|
|
|
|
res.status(200).json(results); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async patch(req, res) { |
|
|
|
|
|
|
|
|
|
|
|
let query = 'UPDATE ?? SET '; |
|
|
|
let query = 'UPDATE ?? SET '; |
|
|
|
let keys = Object.keys(req.body); |
|
|
|
let keys = Object.keys(req.body); |
|
|
|
|
|
|
|
|
|
|
@ -449,6 +468,44 @@ class Xapi { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// async update(req, res) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// let query = 'UPDATE ?? SET ';
|
|
|
|
|
|
|
|
// let keys = Object.keys(req.body);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // SET clause
|
|
|
|
|
|
|
|
// let updateKeys = '';
|
|
|
|
|
|
|
|
// for (let i = 0; i < keys.length; ++i) {
|
|
|
|
|
|
|
|
// updateKeys += keys[i] + ' = ? '
|
|
|
|
|
|
|
|
// if (i !== keys.length - 1)
|
|
|
|
|
|
|
|
// updateKeys += ', '
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // where clause
|
|
|
|
|
|
|
|
// query += updateKeys + ' where '
|
|
|
|
|
|
|
|
// let clause = this.mysql.getPrimaryKeyWhereClause(req.app.locals._tableName,
|
|
|
|
|
|
|
|
// req.params.id.split('___'));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (!clause) {
|
|
|
|
|
|
|
|
// return res.status(400).send({
|
|
|
|
|
|
|
|
// error: "Table is made of composite primary keys - all keys were not in input"
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// query += clause;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // params
|
|
|
|
|
|
|
|
// let params = [];
|
|
|
|
|
|
|
|
// params.push(req.app.locals._tableName);
|
|
|
|
|
|
|
|
// params = params.concat(Object.values(req.body));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// let results = await this.mysql.exec(query, params);
|
|
|
|
|
|
|
|
// res.status(200).json(results);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
async delete(req, res) { |
|
|
|
async delete(req, res) { |
|
|
|
|
|
|
|
|
|
|
|
let query = 'DELETE FROM ?? WHERE '; |
|
|
|
let query = 'DELETE FROM ?? WHERE '; |
|
|
|