diff --git a/examples/node/get-user-count.js b/examples/node/get-user-count.js new file mode 100644 index 00000000..051ec209 --- /dev/null +++ b/examples/node/get-user-count.js @@ -0,0 +1,38 @@ +/** + * Logs in, returns number of active users + */ + +var ApiFactory = require('./../../').ApiFactory; +var ApiConstants = require('./../../').ApiConstants; +var util = require('util'); + +var instance = ApiFactory.getInstance({ + hostname: 'localhost', + version: '5.0', + port: 8080 +}); + +util.print('Logs in, returns number of active users\n'); +util.log('Logging in ...'); +instance.login('new@user.attask', 'user').then( + function() { + util.log('Getting number of active users ...'); + var query = {}; + query['isActive'] = true; + query['isActive' + ApiConstants.MOD] = ApiConstants.Operators.EQUAL; + instance.count('user', query).then( + function(data) { + util.log('Get success. Received data:'); + console.log(util.inspect(data, {colors:true})); + }, + function(error) { + util.log('Get failure. Received data:'); + console.log(util.inspect(error, {colors:true})); + } + ); + }, + function(error) { + util.log('Login failure. Received data:'); + console.log(util.inspect(error, {colors:true})); + } +);