Skip to content

Commit d91c2fa

Browse files
committed
added support for ids beginning with internal prefix, such as $$USER
1 parent 56e8ca2 commit d91c2fa

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/ApiConstants.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ var ApiConstants = {
103103
*/
104104
ROLLUP: "$$ROLLUP",
105105

106+
/**
107+
* Prefix for constants.
108+
* @readonly
109+
* @type {String}
110+
*/
111+
INTERNAL_PREFIX: '$$',
112+
106113
/**
107114
* Values which can be used as wildcards
108115
* @readonly

src/plugins/get.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,34 @@
1818
* @author Hovhannes Babayan <bhovhannes at gmail dot com>
1919
* @author Sassoun Derderian <citizen.sas at gmail dot com>
2020
*/
21+
22+
var ApiConstants = require('./../ApiConstants');
23+
2124
module.exports = function(Api) {
2225
/**
2326
* Used for retrieve an object or multiple objects.
2427
* @memberOf Workfront.Api
2528
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
2629
* @param {String|Array} objIDs Either one or multiple object ids
27-
* @param {Object} fields Which fields to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
30+
* @param {String|String[]} fields Which fields to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
2831
* @return {Promise} A promise which will resolved with results if everything went ok and rejected otherwise
2932
*/
3033
Api.prototype.get = function (objCode, objIDs, fields) {
3134
if (typeof objIDs === 'string') {
3235
objIDs = [objIDs];
3336
}
37+
var endPoint = objCode,
38+
params = null;
3439
if (objIDs.length === 1) {
35-
return this.request(objCode + '/' + objIDs[0], null, fields, Api.Methods.GET);
40+
if (objIDs[0].indexOf(ApiConstants.INTERNAL_PREFIX) === 0) {
41+
params = {id: objIDs[0]};
42+
}
43+
else {
44+
endPoint += '/' + objIDs[0];
45+
}
3646
} else {
37-
return this.request(objCode, {id: objIDs}, fields, Api.Methods.GET);
47+
params = {id: objIDs};
3848
}
49+
return this.request(endPoint, params, fields, Api.Methods.GET);
3950
};
4051
};

test/plugins/get.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ describe('Api.get() method', function() {
5151
expect(actualReturnedValue).to.equal(expectedReturnValue);
5252
});
5353

54+
it('should call request() with proper params and return value received from request() if called with single objId (String) containing internal prefix', function() {
55+
var objId = '$$USER';
56+
57+
var fields = [
58+
'*', "zzz:*"
59+
];
60+
61+
var objCode = 'baz';
62+
63+
var expectedReturnValue = 123;
64+
api.request.returns(expectedReturnValue);
65+
66+
var actualReturnedValue = api.get(objCode, objId, fields);
67+
expect(api.request).to.have.callCount(1);
68+
expect(api.request).to.have.been.calledWith(objCode, {id:objId}, fields, "GET");
69+
expect(actualReturnedValue).to.equal(expectedReturnValue);
70+
});
71+
5472
it('should call request() with proper params and return value received from request() if called with single objId (Array)', function() {
5573
var objId = ['myid'];
5674

0 commit comments

Comments
 (0)