diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..75ee422162 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,4 @@ +## Contribution guidelines +- Try to keep it close to original design. Key idea here being zero configuration. So automate by going out of the way. +- Tests to cover new functionality. +- If the issue is a major or large change. Please create a PR issue before working on it. diff --git a/README.md b/README.md index 9072e0842a..c0b4498d7e 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Hence this. # Setup and Usage +xmysql requires node >= 7.6.0 + ``` npm install -g xmysql ``` @@ -170,6 +172,9 @@ By default 20 records and max of 100 are returned per GET request on a table. /api/payments?_p=2&_size=50 ``` +When _size is greater than 100 - number of records defaults to 100 (i.e maximum) + +When _size is less than or equal to 0 - number of records defaults to 20 (i.e minimum) ## Order by / Sorting diff --git a/lib/util/cmd.helper.js b/lib/util/cmd.helper.js index d70b949e82..2b4e50940a 100644 --- a/lib/util/cmd.helper.js +++ b/lib/util/cmd.helper.js @@ -20,6 +20,7 @@ program .option('-d, --database ', 'database schema name') .option('-r, --ipAddress ', 'IP interface of your server / locahost by default') .option('-n, --portNumber ', 'port number for app / 3000 by default') + .option('-o, --port ', 'port number for mysql / 3306 by default') .option('-s, --storageFolder ', 'storage folder / current working dir by default / available only with local') .option('-i, --ignoreTables ', 'comma separated table names to ignore') .option('-a, --apiPrefix ', 'api url prefix / "/api/" by default') @@ -53,6 +54,7 @@ exports.handle = program => { /**************** START : default values ****************/ program.ipAddress = program.ipAddress || 'localhost'; program.portNumber = program.portNumber || 3000; + program.port = program.port || 3306; program.user = program.user || 'root'; program.password = program.password || ''; program.host = program.host || 'localhost'; diff --git a/lib/xapi.js b/lib/xapi.js index 032fde41b0..66d952010a 100644 --- a/lib/xapi.js +++ b/lib/xapi.js @@ -148,7 +148,7 @@ class Xapi { stat.apis += resources[j]['routes'].length - // iterate over rach routes in resource and map function + // iterate over each routes in resource and map function for (var i = 0; i < routes.length; ++i) { switch (routes[i]['routeType']) { diff --git a/lib/xsql.js b/lib/xsql.js index e590380cb9..f0089871da 100644 --- a/lib/xsql.js +++ b/lib/xsql.js @@ -193,10 +193,15 @@ class Xsql { reqParams._index = 0; reqParams._len = 20; - if ('_size' in reqParams && parseInt(reqParams._size) < 100) { - reqParams._len = parseInt(reqParams._size) + if('_size' in reqParams) { + if (parseInt(reqParams._size) > 0 && parseInt(reqParams._size) <= 100) { + reqParams._len = parseInt(reqParams._size) + } else if (parseInt(reqParams._size) > 100) { + reqParams._len = 100 + } } + if ('_p' in reqParams && parseInt(reqParams._p) > 0) { reqParams._index = (parseInt(reqParams._p) - 1) * reqParams._len; } diff --git a/package.json b/package.json index 43a870f994..78a759ff10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xmysql", - "version": "0.4.4", + "version": "0.4.5", "description": "One command to generate REST APIs for any MySql database", "main": "index.js", "scripts": { diff --git a/tests/tests.js b/tests/tests.js index a97259ac5c..7f5cf1137b 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -241,6 +241,89 @@ describe('xmysql : tests', function () { }); + + it('GET ' + apiPrefix + 'customers should PASS', function (done) { + + //http get an url + agent.get(apiPrefix + 'customers') // api url + .expect(200) // 2xx for success and 4xx for failure + .end(function (err, res) { + // Handle /api/tables error + if (err) { + return done(err); + } + + //validate response + res.body.length.should.be.equal(20); + + return done(); + + }); + + }); + + it('GET ' + apiPrefix + 'customers?_size=100 should PASS', function (done) { + + //http get an url + agent.get(apiPrefix + 'customers?_size=100') // api url + .expect(200) // 2xx for success and 4xx for failure + .end(function (err, res) { + // Handle /api/tables error + if (err) { + return done(err); + } + + //validate response + res.body.length.should.be.equal(100); + + return done(); + + }); + + }); + + it('GET ' + apiPrefix + 'customers?_size=1000 should PASS', function (done) { + + //http get an url + agent.get(apiPrefix + 'customers?_size=1000') // api url + .expect(200) // 2xx for success and 4xx for failure + .end(function (err, res) { + // Handle /api/tables error + if (err) { + return done(err); + } + + //validate response + res.body.length.should.be.equal(100); + + return done(); + + }); + + }); + + it('GET ' + apiPrefix + 'customers?_size=-1 should PASS', function (done) { + + //http get an url + agent.get(apiPrefix + 'customers?_size=-1') // api url + .expect(200) // 2xx for success and 4xx for failure + .end(function (err, res) { + // Handle /api/tables error + if (err) { + return done(err); + } + + //validate response + res.body.length.should.be.equal(20); + + return done(); + + }); + + }); + + + it('GET ' + apiPrefix + 'payments?_p=2&_size=10 should PASS', function (done) { //http get an url