Skip to content

Commit

Permalink
added report() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Hovhannes Babayan committed Jan 9, 2015
1 parent a547ea2 commit bc8150e
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 7 deletions.
42 changes: 40 additions & 2 deletions dist/attask.js
Original file line number Diff line number Diff line change
Expand Up @@ -6634,6 +6634,38 @@ var ApiConstants = {
*/
DATAEXTENSION: "DE:",

/**
* Suffix for specifying which fields will be added to the GROUP BY clause in a ReportQuery. Value is "_GroupBy".
* @readonly
* @type {String}
*/
GROUPBY: "_GroupBy",

/**
* Suffix for specifying force "_GroupBy". Value is "$$_ForceGroupBy".
*/
FORCE_GROUPBY: "$$_ForceGroupBy",

/**
* Suffix for specifying aggregate functions in a ReportQuery. Value is "_AggFunc".
*/
AGGFUNC: "_AggFunc",

/**
* Suffix for specifying comma-separated list of aggregated currency fields for the report
*/
AGGCURRENCY_FIELDS: "$$AggCurr",
GROUPCURRENCY_FIELDS: "$$GroupCurr",


SORTCURRENCY_FIELDS: "$$SortCurr",
FILTERCURRENCY_FIELDS: "$$FilterCurr",

/**
* Key used to specify that a GROUP BY query should be done WITH ROLLUP. Value is "$$ROLLUP"
*/
ROLLUP: "$$ROLLUP",

/**
* Values which can be used as wildcards
* @readonly
Expand Down Expand Up @@ -7306,8 +7338,14 @@ module.exports = function(Api) {
};
},{}],51:[function(require,module,exports){
module.exports = function(Api) {
Api.prototype.report = function () {
throw new Error('Not implemented')
/**
* Performs report request, where only the aggregate of some field is desired, with one or more groupings.
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|AtTask API Explorer}
* @param {Object} query An object with search criteria and aggregate functions
* @return {Promise} A promise which will resolved with results if everything went ok and rejected otherwise
*/
Api.prototype.report = function (objCode, query) {
return this.request(objCode + '/report', query, null, Api.Methods.GET);
};
};
},{}],52:[function(require,module,exports){
Expand Down
6 changes: 3 additions & 3 deletions dist/attask.min.js

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions examples/node/report-project-hours.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Logs in, then returns list of hours grouped by project names
*/

var ApiFactory = require('./../../').ApiFactory;
var ApiConstants = require('./../../').ApiConstants;
var util = require('util');

var instance = ApiFactory.getInstance({
url: 'http://localhost:8080',
version: '4.0'
});

util.print('Logs in, then returns list of hours grouped by project names\n');
util.log('Logging in ...');
instance.login('new@user.attask', 'user').then(
function(data) {
util.log('Running report ...');
var query = {};
query['project:name_1' + ApiConstants.GROUPBY] = true;
query['hours' + ApiConstants.AGGFUNC] = ApiConstants.Functions.SUM;
instance.report('hour', query).then(
function(data) {
util.log('Report success. Received data:');
console.log(util.inspect(data, {colors:true}));
},
function(error) {
util.log('Report 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}));
}
);
32 changes: 32 additions & 0 deletions src/ApiConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ var ApiConstants = {
*/
DATAEXTENSION: "DE:",

/**
* Suffix for specifying which fields will be added to the GROUP BY clause in a ReportQuery. Value is "_GroupBy".
* @readonly
* @type {String}
*/
GROUPBY: "_GroupBy",

/**
* Suffix for specifying force "_GroupBy". Value is "$$_ForceGroupBy".
*/
FORCE_GROUPBY: "$$_ForceGroupBy",

/**
* Suffix for specifying aggregate functions in a ReportQuery. Value is "_AggFunc".
*/
AGGFUNC: "_AggFunc",

/**
* Suffix for specifying comma-separated list of aggregated currency fields for the report
*/
AGGCURRENCY_FIELDS: "$$AggCurr",
GROUPCURRENCY_FIELDS: "$$GroupCurr",


SORTCURRENCY_FIELDS: "$$SortCurr",
FILTERCURRENCY_FIELDS: "$$FilterCurr",

/**
* Key used to specify that a GROUP BY query should be done WITH ROLLUP. Value is "$$ROLLUP"
*/
ROLLUP: "$$ROLLUP",

/**
* Values which can be used as wildcards
* @readonly
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/report.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module.exports = function(Api) {
Api.prototype.report = function () {
throw new Error('Not implemented')
/**
* Performs report request, where only the aggregate of some field is desired, with one or more groupings.
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|AtTask API Explorer}
* @param {Object} query An object with search criteria and aggregate functions
* @return {Promise} A promise which will resolved with results if everything went ok and rejected otherwise
*/
Api.prototype.report = function (objCode, query) {
return this.request(objCode + '/report', query, null, Api.Methods.GET);
};
};
36 changes: 36 additions & 0 deletions test/plugins/report.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require('./../common');

var Api = require('./../../').Api;
var ApiConstants = require('./../../').ApiConstants;


describe('Api.report() method', function() {

var api;
var url = 'http://foobar:8080';

beforeEach(function () {
api = new Api({url: url});
sinon.stub(api, "request");
});

afterEach(function () {
api.request.restore(); // Unwraps the spy
});

it('should call request() with proper params and return value received from request()', function() {
var query = {
'foo': 'bar'
};

var objCode = 'baz';

var expectedReturnValue = 123;
api.request.returns(expectedReturnValue);

var actualReturnedValue = api.report(objCode, query);
expect(api.request).to.have.callCount(1);
expect(api.request).to.have.been.calledWith(objCode + "/report", query, null, "GET");
expect(actualReturnedValue).to.equal(expectedReturnValue);
});
});

0 comments on commit bc8150e

Please sign in to comment.