comprodls-sdk 2.11.7 → 2.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +28 -28
- package/.npmignore +5 -0
- package/README.md +371 -371
- package/dist/comprodls-sdk.js +11493 -11301
- package/dist/comprodls-sdk.min.js +18 -18
- package/grunt/publish.js +148 -148
- package/lib/comprodls.js +146 -146
- package/lib/config/index.js +337 -336
- package/lib/helpers/index.js +29 -29
- package/lib/helpers/lib/api/converter.js +119 -119
- package/lib/helpers/lib/api/index.js +120 -120
- package/lib/helpers/lib/api/validations.js +72 -72
- package/lib/helpers/lib/errors.js +129 -129
- package/lib/helpers/lib/utils.js +23 -23
- package/lib/helpers/lib/validator.js +100 -100
- package/lib/open_access/index.js +121 -121
- package/lib/services/activity/activity.js +209 -209
- package/lib/services/activity/attempt.js +431 -431
- package/lib/services/activity/index.js +28 -28
- package/lib/services/analytics/index.js +1555 -1555
- package/lib/services/attempts/index.js +342 -342
- package/lib/services/auth/classProduct.js +37 -37
- package/lib/services/auth/index.js +2541 -2535
- package/lib/services/collab/index.js +468 -468
- package/lib/services/drive/index.js +144 -144
- package/lib/services/integrations/index.js +279 -116
- package/lib/services/invitations/index.js +313 -313
- package/lib/services/lrs/index.js +459 -459
- package/lib/services/product/index.js +267 -267
- package/lib/services/pub/index.js +407 -407
- package/lib/services/push/index.js +187 -187
- package/lib/services/push/pubnubClientWrapper.js +557 -557
- package/lib/services/push/sessionStorage.js +64 -64
- package/lib/services/pushX/index.js +190 -190
- package/lib/services/pushX/pubnubClientWrapper.js +211 -211
- package/lib/services/sisevents/index.js +113 -113
- package/lib/services/spaces/index.js +976 -929
- package/lib/services/superuser/index.js +175 -175
- package/lib/services/workflows/index.js +464 -464
- package/lib/services/xapi/index.js +232 -232
- package/lib/token/index.js +114 -114
- package/lib/token/validations.js +88 -88
- package/package-lock.json +5095 -0
- package/package.json +1 -1
- package/test.js +50 -50
- package/.vscode/launch.json +0 -23
- package/npm-debug.log.189866131 +0 -0
- package/npm-debug.log.712840116 +0 -26
|
@@ -1,1555 +1,1555 @@
|
|
|
1
|
-
/*************************************************************************
|
|
2
|
-
*
|
|
3
|
-
* COMPRO CONFIDENTIAL
|
|
4
|
-
* __________________
|
|
5
|
-
*
|
|
6
|
-
* [2015] - [2020] Compro Technologies Private Limited
|
|
7
|
-
* All Rights Reserved.
|
|
8
|
-
*
|
|
9
|
-
* NOTICE: All information contained herein is, and remains
|
|
10
|
-
* the property of Compro Technologies Private Limited. The
|
|
11
|
-
* intellectual and technical concepts contained herein are
|
|
12
|
-
* proprietary to Compro Technologies Private Limited and may
|
|
13
|
-
* be covered by U.S. and Foreign Patents, patents in process,
|
|
14
|
-
* and are protected by trade secret or copyright law.
|
|
15
|
-
*
|
|
16
|
-
* Dissemination of this information or reproduction of this material
|
|
17
|
-
* is strictly forbidden unless prior written permission is obtained
|
|
18
|
-
* from Compro Technologies Pvt. Ltd..
|
|
19
|
-
***************************************************************************/
|
|
20
|
-
|
|
21
|
-
/***********************************************************
|
|
22
|
-
* comproDLS SDK Analytics API Adaptor
|
|
23
|
-
* Functions for calling Analytics API.
|
|
24
|
-
************************************************************/
|
|
25
|
-
|
|
26
|
-
/*********************************
|
|
27
|
-
* Setting Up Module Entry Point
|
|
28
|
-
**********************************/
|
|
29
|
-
|
|
30
|
-
var q = require('q');
|
|
31
|
-
var request = require('superagent');
|
|
32
|
-
|
|
33
|
-
var helpers = require('../../helpers');
|
|
34
|
-
var DLSError = helpers.errors.DLSError;
|
|
35
|
-
|
|
36
|
-
module.exports = analytics;
|
|
37
|
-
|
|
38
|
-
/*********************************
|
|
39
|
-
* Public Function definitions
|
|
40
|
-
**********************************/
|
|
41
|
-
function analytics() {
|
|
42
|
-
return {
|
|
43
|
-
archiveUserAnalytics: archiveUserAnalytics.bind(this),
|
|
44
|
-
getArchivedUserAnalytics: getArchivedUserAnalytics.bind(this),
|
|
45
|
-
|
|
46
|
-
getOrgAnalyticsStat: getOrgAnalyticsStat.bind(this),
|
|
47
|
-
|
|
48
|
-
getClassAnalytics: getClassAnalytics.bind(this),
|
|
49
|
-
getClassProductRecentPendingSubmissions: getClassProductRecentPendingSubmissions.bind(this),
|
|
50
|
-
getClassRecordUserAggregations: getClassRecordUserAggregations.bind(this),
|
|
51
|
-
getClassRecord: getClassRecord.bind(this),
|
|
52
|
-
getClassRecordItemAggregations: getClassRecordItemAggregations.bind(this),
|
|
53
|
-
getShowcaseRecordOfAClass: getShowcaseRecordOfAClass.bind(this),
|
|
54
|
-
|
|
55
|
-
getGroupRecord: getGroupRecord.bind(this),
|
|
56
|
-
getClassGroupsRecentPendingSubmissions: getClassGroupsRecentPendingSubmissions.bind(this),
|
|
57
|
-
getGroupsWithEvaluatedOnce: getGroupsWithEvaluatedOnce.bind(this),
|
|
58
|
-
|
|
59
|
-
getUserProductAnalytics: getUserProductAnalytics.bind(this),
|
|
60
|
-
getUserProductAnalyticById: getUserProductAnalyticById.bind(this),
|
|
61
|
-
getExternalDataForUserAnalyticItem: getExternalDataForUserAnalyticItem.bind(this),
|
|
62
|
-
searchUserProductAnalytics: searchUserProductAnalytics.bind(this),
|
|
63
|
-
getUserClassRecentSubmissions: getUserClassRecentSubmissions.bind(this),
|
|
64
|
-
getStudentsWithEvaluatedOnce: getStudentsWithEvaluatedOnce.bind(this),
|
|
65
|
-
|
|
66
|
-
getAppState: getAppState.bind(this),
|
|
67
|
-
updateAppState: updateAppState.bind(this),
|
|
68
|
-
deleteAppState: deleteAppState.bind(this),
|
|
69
|
-
|
|
70
|
-
getQuestionProgressByLearningObjective: getQuestionProgressByLearningObjective.bind(this),
|
|
71
|
-
|
|
72
|
-
//AssignedPaths Related APIs
|
|
73
|
-
getAllAssignedPathsOfClass: getAllAssignedPathsOfClass.bind(this),
|
|
74
|
-
getMyAssignedPathsOfClass: getMyAssignedPathsOfClass.bind(this),
|
|
75
|
-
getAssignedPathAnalytics: getAssignedPathAnalytics.bind(this),
|
|
76
|
-
getMyParticularAssignedPathOfClass: getMyParticularAssignedPathOfClass.bind(this)
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
//options = {
|
|
81
|
-
// type: 'users/classes', // choose any one
|
|
82
|
-
// range: '', //
|
|
83
|
-
// start: '', // time(ms) - start interval
|
|
84
|
-
// end: '', // time(ms) - end interval
|
|
85
|
-
// role: '', // The role of users i.e. student, teacher, etc. No default role (i.e. all users).
|
|
86
|
-
// shadow: <boolean> // if user/class is shadow-provsioined.
|
|
87
|
-
//}
|
|
88
|
-
function getOrgAnalyticsStat(options) {
|
|
89
|
-
var self = this;
|
|
90
|
-
|
|
91
|
-
//Initializing promise
|
|
92
|
-
var dfd = q.defer();
|
|
93
|
-
//Validations
|
|
94
|
-
var err = {};
|
|
95
|
-
if(options && options.type) {
|
|
96
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
97
|
-
if(err) { dfd.reject(err); }
|
|
98
|
-
else {
|
|
99
|
-
err = {};
|
|
100
|
-
var allowedAnalyticsDataType = ['users', 'classes'];
|
|
101
|
-
if(allowedAnalyticsDataType.indexOf(options.type) > -1) {
|
|
102
|
-
//Passed all validations, Construct API url
|
|
103
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
104
|
-
self.config.ANALYTICS_API_URLS.getOrgAnalyticsStat;
|
|
105
|
-
url = helpers.api.constructAPIUrl(url, {
|
|
106
|
-
orgId: self.orgId, type: options.type
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
var params = {};
|
|
110
|
-
if(options) {
|
|
111
|
-
if(options.range) { params.range = options.range; }
|
|
112
|
-
if(options.start) { params.start = options.start; }
|
|
113
|
-
if(options.end) { params.end = options.end; }
|
|
114
|
-
if(options.role) { params.role = options.role; }
|
|
115
|
-
if(options.shadow) { params.shadow = options.shadow; }
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
//Setup request with URL and Params
|
|
119
|
-
var requestAPI = request.get(url).query(params);
|
|
120
|
-
|
|
121
|
-
//Setup token in Authorization header
|
|
122
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
123
|
-
|
|
124
|
-
// setting up traceid
|
|
125
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
126
|
-
|
|
127
|
-
//Call Product Timespent Api
|
|
128
|
-
requestAPI.end(function(err, response) {
|
|
129
|
-
if(err) {
|
|
130
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
131
|
-
dfd.reject(err);
|
|
132
|
-
}
|
|
133
|
-
else { dfd.resolve(response.body); }
|
|
134
|
-
});
|
|
135
|
-
} else {
|
|
136
|
-
err.message = err.description = 'Type: ' + options.type + ' is not supported';
|
|
137
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
138
|
-
dfd.reject(err);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
} else {
|
|
142
|
-
err.message = err.description = 'type not found in request options';
|
|
143
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
144
|
-
dfd.reject(err);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return dfd.promise;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
//options = {
|
|
151
|
-
// type: 'string', // [items/summary]
|
|
152
|
-
// userid: 'string', // user uuid
|
|
153
|
-
// productcode: 'string, // product code
|
|
154
|
-
// classid: 'string', // OPTIONAL
|
|
155
|
-
// itemcode: 'string', // OPTIONAL (only for 'type=items') item-code of the required item
|
|
156
|
-
// metrics: boolean // OPTIONAL (only for 'type=items') true/false - aggregations on the
|
|
157
|
-
// item(s), default - true
|
|
158
|
-
// history: boolean // If history is true - submission is array else submission is object
|
|
159
|
-
// expiredView: boolean // If expiredView is true - items from class record matrix will be returned.
|
|
160
|
-
// externalData: boolean // OPTIONAL(default is 'false' - only works with itemcode) whether to return external
|
|
161
|
-
//secondary evaluation data or not.
|
|
162
|
-
// group: boolean // If group is true - then it will return group data from P1.
|
|
163
|
-
//}
|
|
164
|
-
function getUserProductAnalytics(options) {
|
|
165
|
-
var self = this;
|
|
166
|
-
|
|
167
|
-
//Initializing promise
|
|
168
|
-
var dfd = q.defer();
|
|
169
|
-
//Validations
|
|
170
|
-
var err = {};
|
|
171
|
-
if(options && options.type && options.userid && options.productcode) {
|
|
172
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
173
|
-
if(err) { dfd.reject(err); }
|
|
174
|
-
else {
|
|
175
|
-
var supportedType = ['items', 'summary'];
|
|
176
|
-
//Passed all validations, Construct API url
|
|
177
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'];
|
|
178
|
-
|
|
179
|
-
if(supportedType.indexOf(options.type) > -1) {
|
|
180
|
-
switch(options.type) {
|
|
181
|
-
case 'items':
|
|
182
|
-
url += self.config.ANALYTICS_API_URLS.getAnalyticProductItems;
|
|
183
|
-
break;
|
|
184
|
-
case 'summary':
|
|
185
|
-
url += self.config.ANALYTICS_API_URLS.getAnalyticProductSummary;
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
189
|
-
|
|
190
|
-
var params = { userid: options.userid, productcode: options.productcode };
|
|
191
|
-
|
|
192
|
-
if(options.classid) { params.classid = options.classid; }
|
|
193
|
-
if(options.itemcode) { params.itemcode = options.itemcode; }
|
|
194
|
-
if(options.metrics) { params.metrics = options.metrics; }
|
|
195
|
-
if(options.history) { params.history = options.history; }
|
|
196
|
-
if(options.group) { params.group = options.group; }
|
|
197
|
-
if(options.externalData) { params.externalData = options.externalData; }
|
|
198
|
-
if(options.expiredView && options.type === 'items') { params.expiredView = options.expiredView; }
|
|
199
|
-
|
|
200
|
-
//Setup request with URL and Params
|
|
201
|
-
var requestAPI = request.get(url).query(params);
|
|
202
|
-
|
|
203
|
-
//Setup token in Authorization header
|
|
204
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
205
|
-
|
|
206
|
-
// setting up traceid
|
|
207
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
208
|
-
|
|
209
|
-
//Call Product Timespent Api
|
|
210
|
-
requestAPI.end(function(err, response) {
|
|
211
|
-
if(err) {
|
|
212
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
213
|
-
dfd.reject(err);
|
|
214
|
-
}
|
|
215
|
-
else { dfd.resolve(response.body); }
|
|
216
|
-
});
|
|
217
|
-
} else {
|
|
218
|
-
err.message = err.description = options.type + " is not a valid value of option 'type'";
|
|
219
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
220
|
-
dfd.reject(err);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
} else {
|
|
224
|
-
err.message = err.description = "Required parameter 'type' or 'userid' or " +
|
|
225
|
-
"'productcode' not found in request options";
|
|
226
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
227
|
-
dfd.reject(err);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return dfd.promise;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
//options = {
|
|
234
|
-
// userprogressid: 'string' // userprogressid
|
|
235
|
-
//}
|
|
236
|
-
function getUserProductAnalyticById(options) {
|
|
237
|
-
var self = this;
|
|
238
|
-
|
|
239
|
-
//Initializing promise
|
|
240
|
-
var dfd = q.defer();
|
|
241
|
-
//Validations
|
|
242
|
-
var err = {};
|
|
243
|
-
if(options && options.userprogressid) {
|
|
244
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
245
|
-
if(err) { dfd.reject(err); }
|
|
246
|
-
else {
|
|
247
|
-
//Passed all validations, Construct API url
|
|
248
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
249
|
-
self.config.ANALYTICS_API_URLS.getAnalyticProductById;
|
|
250
|
-
url = helpers.api.constructAPIUrl(url, {
|
|
251
|
-
orgId: self.orgId, userProgressId: options.userprogressid
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
//Setup request with URL and Params
|
|
255
|
-
var requestAPI = request.get(url);
|
|
256
|
-
|
|
257
|
-
//Setup token in Authorization header
|
|
258
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
259
|
-
|
|
260
|
-
// setting up traceid
|
|
261
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
262
|
-
|
|
263
|
-
//Call Product Timespent Api
|
|
264
|
-
requestAPI.end(function(err, response) {
|
|
265
|
-
if(err) {
|
|
266
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
267
|
-
dfd.reject(err);
|
|
268
|
-
}
|
|
269
|
-
else { dfd.resolve(response.body); }
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
} else {
|
|
273
|
-
err.message = err.description = "Required parameter 'userprogressid' not " +
|
|
274
|
-
"found in request options";
|
|
275
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
276
|
-
dfd.reject(err);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return dfd.promise;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
//options = {
|
|
283
|
-
// ext_user_id: <ext_user_id>, // mandatory
|
|
284
|
-
// productcode: <productcode>, // mandatory
|
|
285
|
-
// itemcode: <itemcode>, // mandatory
|
|
286
|
-
// submission_order: number, // mandatory
|
|
287
|
-
// part: number, // mandatory
|
|
288
|
-
// classid: <classid>, // optional
|
|
289
|
-
//}
|
|
290
|
-
function getExternalDataForUserAnalyticItem(options) {
|
|
291
|
-
var self = this;
|
|
292
|
-
var dfd = q.defer();
|
|
293
|
-
// Validations
|
|
294
|
-
var err = {};
|
|
295
|
-
if(options && options.ext_user_id && options.productcode && options.itemcode &&
|
|
296
|
-
options.submission_order && options.part) {
|
|
297
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
298
|
-
if(err) { dfd.reject(err); }
|
|
299
|
-
else {
|
|
300
|
-
// Passed all validations, Construct API url
|
|
301
|
-
var url = self.config.DEFAULT_HOSTS.ANALYTICS +
|
|
302
|
-
self.config.ANALYTICS_API_URLS.getExternalDataForUserAnalyticItem;
|
|
303
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
304
|
-
|
|
305
|
-
var params = {
|
|
306
|
-
ext_user_id: options.ext_user_id,
|
|
307
|
-
productcode: options.productcode,
|
|
308
|
-
itemcode: options.itemcode,
|
|
309
|
-
submission_order: options.submission_order,
|
|
310
|
-
part: options.part
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
if(options.classid) { params.classid = options.classid; }
|
|
314
|
-
|
|
315
|
-
// Setup request with URL and Params
|
|
316
|
-
var requestAPI = request.get(url).query(params);
|
|
317
|
-
|
|
318
|
-
// Setup token in Authorization header
|
|
319
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
320
|
-
|
|
321
|
-
// setting up traceid
|
|
322
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
323
|
-
|
|
324
|
-
// Call Product Timespent Api
|
|
325
|
-
requestAPI.end(function(err, response) {
|
|
326
|
-
if(err) {
|
|
327
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
328
|
-
dfd.reject(err);
|
|
329
|
-
}
|
|
330
|
-
else { dfd.resolve(response.body); }
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
} else {
|
|
334
|
-
err.message = err.description = "Required parameters 'ext_user_id' or 'productcode' or 'itemcode'" +
|
|
335
|
-
" or 'submission_order' or 'part'are not found in request options";
|
|
336
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
337
|
-
dfd.reject(err);
|
|
338
|
-
}
|
|
339
|
-
return dfd.promise;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
//options = {
|
|
343
|
-
// userid: <userid>
|
|
344
|
-
// productid: <productid>,
|
|
345
|
-
// classid: <classid>, // OPTIONAL
|
|
346
|
-
//}
|
|
347
|
-
function archiveUserAnalytics(options) {
|
|
348
|
-
var self = this, err = {};
|
|
349
|
-
//Initializing promise
|
|
350
|
-
var dfd = q.defer();
|
|
351
|
-
if(options && options.userid && options.productid) {
|
|
352
|
-
//Validations
|
|
353
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
354
|
-
if(err) { dfd.reject(err); }
|
|
355
|
-
else {
|
|
356
|
-
var params = {};
|
|
357
|
-
//Passed all validations, Construct API url
|
|
358
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
359
|
-
self.config.ANALYTICS_API_URLS.archiveUserAnalytics;
|
|
360
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
361
|
-
|
|
362
|
-
if(options.userid) { params.userid = options.userid; }
|
|
363
|
-
if(options.productid) { params.productid = options.productid; }
|
|
364
|
-
if(options.classid) { params.classid = options.classid; }
|
|
365
|
-
|
|
366
|
-
//Setup request with URL and Params
|
|
367
|
-
var requestAPI = request.post(url).query(params)
|
|
368
|
-
.set('Content-Type', 'application/json');
|
|
369
|
-
|
|
370
|
-
//Setup token in Authorization header
|
|
371
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
372
|
-
|
|
373
|
-
// setting up traceid
|
|
374
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
375
|
-
|
|
376
|
-
requestAPI.end(function(err, response) {
|
|
377
|
-
if(err) {
|
|
378
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
379
|
-
dfd.reject(err);
|
|
380
|
-
}
|
|
381
|
-
else { dfd.resolve(response.body); }
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
} else {
|
|
385
|
-
err.message = err.description = 'Mandatory parameter [userid, productid] ' +
|
|
386
|
-
'not found in request options';
|
|
387
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
388
|
-
dfd.reject(err);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
return dfd.promise;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
//options = {
|
|
395
|
-
// userid: <userid>, // OPTIONAL
|
|
396
|
-
// productid: <productid>, // OPTIONAL
|
|
397
|
-
// classid: <classid>, // OPTIONAL
|
|
398
|
-
// lookup: 'string', // Search query (',' separated key value pairs), e.g. key1:val1,key2:val2,key3:val3
|
|
399
|
-
// cursor: '', // cursor to next set of documents
|
|
400
|
-
// limit: '' // limit of documents per function call
|
|
401
|
-
//}
|
|
402
|
-
function searchUserProductAnalytics(options) {
|
|
403
|
-
var self = this, err = {};
|
|
404
|
-
//Initializing promise
|
|
405
|
-
var dfd = q.defer();
|
|
406
|
-
|
|
407
|
-
//Validations
|
|
408
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
409
|
-
if(err) { dfd.reject(err); }
|
|
410
|
-
else {
|
|
411
|
-
var params = {};
|
|
412
|
-
//Passed all validations, Construct API url
|
|
413
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
414
|
-
self.config.ANALYTICS_API_URLS.searchUserProductAnalytics;
|
|
415
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
416
|
-
|
|
417
|
-
if(options.userid) { params.userid = options.userid; }
|
|
418
|
-
if(options.productid) { params.productid = options.productid; }
|
|
419
|
-
if(options.classid) { params.classid = options.classid; }
|
|
420
|
-
if(options.lookup) { params.lookup = options.lookup; }
|
|
421
|
-
if(options.cursor) { params.cursor = options.cursor; }
|
|
422
|
-
if(options.limit) { params.limit = options.limit; }
|
|
423
|
-
|
|
424
|
-
//Setup request with URL and Params
|
|
425
|
-
var requestAPI = request.get(url).query(params);
|
|
426
|
-
|
|
427
|
-
//Setup token in Authorization header
|
|
428
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
429
|
-
|
|
430
|
-
// setting up traceid
|
|
431
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
432
|
-
|
|
433
|
-
requestAPI.end(function(err, response) {
|
|
434
|
-
if(err) {
|
|
435
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
436
|
-
dfd.reject(err);
|
|
437
|
-
}
|
|
438
|
-
else { dfd.resolve(response.body); }
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
return dfd.promise;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* This function returns the count and submissions of a user in a class for a product.
|
|
447
|
-
* options = {
|
|
448
|
-
* userid: string,
|
|
449
|
-
* classid: string,
|
|
450
|
-
* productcode: string,
|
|
451
|
-
* gradingStatus: string, // optional, type of submissions required.
|
|
452
|
-
* Possible values: ['not-started', 'submitted', 'evaluated']
|
|
453
|
-
* }
|
|
454
|
-
*/
|
|
455
|
-
function getUserClassRecentSubmissions(options) {
|
|
456
|
-
var self = this;
|
|
457
|
-
var dfd = q.defer(), err = {};
|
|
458
|
-
|
|
459
|
-
if(options && options.classid && options.productcode && options.userid) {
|
|
460
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
461
|
-
if(err) { dfd.reject(err); }
|
|
462
|
-
else {
|
|
463
|
-
// Passed all validations, Constructing URL
|
|
464
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
465
|
-
self.config.ANALYTICS_API_URLS.getUserClassRecentSubmissions;
|
|
466
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
467
|
-
|
|
468
|
-
// Setup Query Params
|
|
469
|
-
var queryParams = {
|
|
470
|
-
userid: options.userid,
|
|
471
|
-
classid: options.classid,
|
|
472
|
-
productcode: options.productcode
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
if(options.gradingStatus) { queryParams.gradingStatus = options.gradingStatus; }
|
|
476
|
-
|
|
477
|
-
// Setup Request with url and params
|
|
478
|
-
var requestAPI = request.get(url).query(queryParams);
|
|
479
|
-
// Setup token in Authorization Header
|
|
480
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
481
|
-
|
|
482
|
-
// setting up traceid
|
|
483
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
484
|
-
|
|
485
|
-
// Call GET Class Product Recent Pending Submissions
|
|
486
|
-
requestAPI.end(function(error, response) {
|
|
487
|
-
if(error) {
|
|
488
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
489
|
-
dfd.reject(err);
|
|
490
|
-
} else {
|
|
491
|
-
dfd.resolve(response.body);
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
else {
|
|
497
|
-
err.message = err.description = 'Mandatory parameters ["classid", "productcode", "userid"]' +
|
|
498
|
-
' not found in request options.';
|
|
499
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
500
|
-
dfd.reject(err);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
return dfd.promise;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
//options = {
|
|
507
|
-
// classid: 'string',
|
|
508
|
-
// productcode: 'string',
|
|
509
|
-
//}
|
|
510
|
-
function getStudentsWithEvaluatedOnce(options) {
|
|
511
|
-
var self = this, err = {};
|
|
512
|
-
//Initializing promise
|
|
513
|
-
var dfd = q.defer();
|
|
514
|
-
if(options && options.classid && options.productcode) {
|
|
515
|
-
//Validations
|
|
516
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
517
|
-
if(err) { dfd.reject(err); }
|
|
518
|
-
else {
|
|
519
|
-
// Passed all validations, Construct API url
|
|
520
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
521
|
-
self.config.ANALYTICS_API_URLS.getStudentsWithEvaluatedOnce;
|
|
522
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
523
|
-
|
|
524
|
-
// Setup params
|
|
525
|
-
var params = {
|
|
526
|
-
classid: options.classid,
|
|
527
|
-
productcode: options.productcode
|
|
528
|
-
};
|
|
529
|
-
// Setup request with URL and Params
|
|
530
|
-
var requestAPI = request.get(url).query(params);
|
|
531
|
-
// Setup token in Authorization header
|
|
532
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
533
|
-
|
|
534
|
-
// setting up traceid
|
|
535
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
536
|
-
|
|
537
|
-
requestAPI.end(function(error, response) {
|
|
538
|
-
if(error) {
|
|
539
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
540
|
-
dfd.reject(err);
|
|
541
|
-
}
|
|
542
|
-
else { dfd.resolve(response.body); }
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
} else {
|
|
546
|
-
err.message = err.description = 'Required parameter classid or ' +
|
|
547
|
-
'productcode not found in request options.';
|
|
548
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
549
|
-
dfd.reject(err);
|
|
550
|
-
}
|
|
551
|
-
return dfd.promise;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
/*options = {
|
|
556
|
-
userid: <userid>, productcode: <productcode>,
|
|
557
|
-
classid: <classid>, // OPTIONAL
|
|
558
|
-
itemcode: <itemcode> // OPTIONAL
|
|
559
|
-
key: <string> // OPTIONAL
|
|
560
|
-
}*/
|
|
561
|
-
function getAppState(options) {
|
|
562
|
-
var self = this;
|
|
563
|
-
var dfd = q.defer();
|
|
564
|
-
// Validations
|
|
565
|
-
var err = {};
|
|
566
|
-
if(options && options.userid && options.productcode) {
|
|
567
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
568
|
-
if(err) { dfd.reject(err); }
|
|
569
|
-
else {
|
|
570
|
-
// Passed all validations, Construct API url
|
|
571
|
-
var url = self.config.DEFAULT_HOSTS.ANALYTICS +
|
|
572
|
-
self.config.ANALYTICS_API_URLS.appState;
|
|
573
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
574
|
-
|
|
575
|
-
var params = { userid: options.userid, productcode: options.productcode };
|
|
576
|
-
if(options.classid) { params.classid = options.classid; }
|
|
577
|
-
if(options.itemcode) { params.itemcode = options.itemcode; }
|
|
578
|
-
if(options.key) { params.key = options.key; }
|
|
579
|
-
|
|
580
|
-
// Setup request with URL and Params
|
|
581
|
-
var requestAPI = request.get(url).query(params);
|
|
582
|
-
|
|
583
|
-
// Setup token in Authorization header
|
|
584
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
585
|
-
|
|
586
|
-
// setting up traceid
|
|
587
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
588
|
-
|
|
589
|
-
// Call Product Timespent Api
|
|
590
|
-
requestAPI.end(function(err, response) {
|
|
591
|
-
if(err) {
|
|
592
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
593
|
-
dfd.reject(err);
|
|
594
|
-
}
|
|
595
|
-
else { dfd.resolve(response.body); }
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
} else {
|
|
599
|
-
err.message = err.description = "Required parameters 'userid' or " +
|
|
600
|
-
"'productcode' are not found in request options";
|
|
601
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
602
|
-
dfd.reject(err);
|
|
603
|
-
}
|
|
604
|
-
return dfd.promise;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
/*options = {
|
|
608
|
-
userid: <userid>,
|
|
609
|
-
productcode: <productcode>,
|
|
610
|
-
classid: <classid>, // OPTIONAL
|
|
611
|
-
itemcode: <itemcode> // OPTIONAL
|
|
612
|
-
appdata: <object>,
|
|
613
|
-
}*/
|
|
614
|
-
function updateAppState(options) {
|
|
615
|
-
var self = this;
|
|
616
|
-
var dfd = q.defer();
|
|
617
|
-
// Validations
|
|
618
|
-
var err = {};
|
|
619
|
-
if(options && options.userid && options.productcode && options.appdata) {
|
|
620
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
621
|
-
if(err) { dfd.reject(err); }
|
|
622
|
-
else {
|
|
623
|
-
// Passed all validations, Construct API url
|
|
624
|
-
var url = self.config.DEFAULT_HOSTS.ANALYTICS +
|
|
625
|
-
self.config.ANALYTICS_API_URLS.appState;
|
|
626
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
627
|
-
|
|
628
|
-
var params = { userid: options.userid, productcode: options.productcode };
|
|
629
|
-
if(options.classid) { params.classid = options.classid; }
|
|
630
|
-
if(options.itemcode) { params.itemcode = options.itemcode; }
|
|
631
|
-
|
|
632
|
-
// Setup request with URL and Params
|
|
633
|
-
var requestAPI = request.put(url).query(params)
|
|
634
|
-
.set('Content-Type', 'application/json')
|
|
635
|
-
.set('Accept', 'application/json')
|
|
636
|
-
.send(options.appdata);
|
|
637
|
-
|
|
638
|
-
// Setup token in Authorization header
|
|
639
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
640
|
-
|
|
641
|
-
// setting up traceid
|
|
642
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
643
|
-
|
|
644
|
-
// Call Product Timespent Api
|
|
645
|
-
requestAPI.end(function(err, response) {
|
|
646
|
-
if(err) {
|
|
647
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
648
|
-
dfd.reject(err);
|
|
649
|
-
}
|
|
650
|
-
else { dfd.resolve(response.body); }
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
} else {
|
|
654
|
-
err.message = err.description = "Required parameters 'userid' or 'appdata'" +
|
|
655
|
-
" or 'productcode' are not found in request options";
|
|
656
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
657
|
-
dfd.reject(err);
|
|
658
|
-
}
|
|
659
|
-
return dfd.promise;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
/*options = {
|
|
663
|
-
userid: <userid>, productcode: <productcode>,
|
|
664
|
-
classid: <classid>, // OPTIONAL
|
|
665
|
-
itemcode: <itemcode> // OPTIONAL
|
|
666
|
-
key: <string> // OPTIONAL
|
|
667
|
-
}*/
|
|
668
|
-
function deleteAppState(options) {
|
|
669
|
-
var self = this;
|
|
670
|
-
var dfd = q.defer();
|
|
671
|
-
// Validations
|
|
672
|
-
var err = {};
|
|
673
|
-
if(options && options.userid && options.productcode) {
|
|
674
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
675
|
-
if(err) { dfd.reject(err); }
|
|
676
|
-
else {
|
|
677
|
-
// Passed all validations, Construct API url
|
|
678
|
-
var url = self.config.DEFAULT_HOSTS.ANALYTICS +
|
|
679
|
-
self.config.ANALYTICS_API_URLS.appState;
|
|
680
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
681
|
-
|
|
682
|
-
var params = { userid: options.userid, productcode: options.productcode };
|
|
683
|
-
if(options.classid) { params.classid = options.classid; }
|
|
684
|
-
if(options.itemcode) { params.itemcode = options.itemcode; }
|
|
685
|
-
if(options.key) { params.key = options.key; }
|
|
686
|
-
|
|
687
|
-
// Setup request with URL and Params
|
|
688
|
-
var requestAPI = request.delete(url).query(params);
|
|
689
|
-
|
|
690
|
-
// Setup token in Authorization header
|
|
691
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
692
|
-
|
|
693
|
-
// setting up traceid
|
|
694
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
695
|
-
|
|
696
|
-
// Call Product Timespent Api
|
|
697
|
-
requestAPI.end(function(err, response) {
|
|
698
|
-
if(err) {
|
|
699
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
700
|
-
dfd.reject(err);
|
|
701
|
-
}
|
|
702
|
-
else { dfd.resolve(response.body); }
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
} else {
|
|
706
|
-
err.message = err.description = "Required parameters 'userid' or " +
|
|
707
|
-
"'productcode' are not found in request options";
|
|
708
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
709
|
-
dfd.reject(err);
|
|
710
|
-
}
|
|
711
|
-
return dfd.promise;
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
/**
|
|
716
|
-
* This function returns the recent pending submissions in a Class for a Product.
|
|
717
|
-
* options = {
|
|
718
|
-
* classid: string,
|
|
719
|
-
* productcode: string,
|
|
720
|
-
* details: boolean, // optional, if details of submissions is also required.
|
|
721
|
-
* limit: number // optional, number of submissions to be fetched at once (default & max is 100)
|
|
722
|
-
* }
|
|
723
|
-
*/
|
|
724
|
-
function getClassProductRecentPendingSubmissions(options) {
|
|
725
|
-
var self = this;
|
|
726
|
-
var dfd = q.defer(), err = {};
|
|
727
|
-
|
|
728
|
-
if(options && options.classid && options.productcode) {
|
|
729
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
730
|
-
if(err) { dfd.reject(err); }
|
|
731
|
-
else {
|
|
732
|
-
// Passed all validations, Constructing URL
|
|
733
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
734
|
-
self.config.ANALYTICS_API_URLS.getClassProductRecentPendingSubmissions;
|
|
735
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
736
|
-
|
|
737
|
-
// Setup Query Params
|
|
738
|
-
var queryParams = {
|
|
739
|
-
classid: options.classid,
|
|
740
|
-
productcode: options.productcode
|
|
741
|
-
};
|
|
742
|
-
|
|
743
|
-
if(options.details) { queryParams.details = options.details; }
|
|
744
|
-
if(options.limit) { queryParams.limit = options.limit; }
|
|
745
|
-
|
|
746
|
-
// Setup Request with url and params
|
|
747
|
-
var requestAPI = request.get(url).query(queryParams);
|
|
748
|
-
// Setup token in Authorization Header
|
|
749
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
750
|
-
// Call GET Class Product Recent Pending Submissions
|
|
751
|
-
|
|
752
|
-
// setting up traceid
|
|
753
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
754
|
-
|
|
755
|
-
requestAPI.end(function(error, response) {
|
|
756
|
-
if(error) {
|
|
757
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
758
|
-
dfd.reject(err);
|
|
759
|
-
} else {
|
|
760
|
-
dfd.resolve(response.body);
|
|
761
|
-
}
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
else {
|
|
766
|
-
err.message = err.description = 'Mandatory parameters ["classid", "productcode"] not found in ' +
|
|
767
|
-
'request options.';
|
|
768
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
769
|
-
dfd.reject(err);
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
return dfd.promise;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
/*options = {
|
|
776
|
-
* classid: 'string', // class uuid
|
|
777
|
-
* productcode: 'string', // product code
|
|
778
|
-
* includeContext: 'boolean' // includse context or heirarchy (optional)
|
|
779
|
-
*}
|
|
780
|
-
*/
|
|
781
|
-
function getClassRecord(options) {
|
|
782
|
-
var self = this;
|
|
783
|
-
|
|
784
|
-
//Initializing DFD
|
|
785
|
-
var dfd = q.defer(), err = {};
|
|
786
|
-
|
|
787
|
-
// Validations
|
|
788
|
-
if(options && options.classid && options.productcode) {
|
|
789
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
790
|
-
if(err){ dfd.reject(err); }
|
|
791
|
-
else {
|
|
792
|
-
// Passed all validations, Constructing URL
|
|
793
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] + self.config.ANALYTICS_API_URLS.getClassRecord;
|
|
794
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
795
|
-
|
|
796
|
-
// Setup Query Params
|
|
797
|
-
var queryParams = {
|
|
798
|
-
classid: options.classid,
|
|
799
|
-
productcode: options.productcode,
|
|
800
|
-
includeContext: options.includeContext
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
// Setup Request with url and params
|
|
804
|
-
var requestAPI = request.get(url).query(queryParams);
|
|
805
|
-
// Setup token in Authorization Header
|
|
806
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
807
|
-
|
|
808
|
-
// setting up traceid
|
|
809
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
810
|
-
|
|
811
|
-
// Call GET GET CLASS RECORD ITEM
|
|
812
|
-
requestAPI.end(function(error, response) {
|
|
813
|
-
if(error) {
|
|
814
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
815
|
-
dfd.reject(err);
|
|
816
|
-
} else {
|
|
817
|
-
dfd.resolve(response.body)
|
|
818
|
-
}
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
} else {
|
|
822
|
-
err.message = err.description = 'Required parameter classid or ' +
|
|
823
|
-
'productcode not found in request options.';
|
|
824
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
825
|
-
dfd.reject(err);
|
|
826
|
-
}
|
|
827
|
-
return dfd.promise;
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
/*options = {
|
|
831
|
-
* classid: 'string', // class uuid
|
|
832
|
-
* productcode: 'string', // product code
|
|
833
|
-
* item-code: 'string' // item-code of item(optional)
|
|
834
|
-
*}
|
|
835
|
-
*/
|
|
836
|
-
function getClassRecordItemAggregations(options) {
|
|
837
|
-
var self = this;
|
|
838
|
-
|
|
839
|
-
//Initializing DFD
|
|
840
|
-
var dfd = q.defer(), err = {};
|
|
841
|
-
|
|
842
|
-
// Validations
|
|
843
|
-
if(options && options.classid && options.productcode) {
|
|
844
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
845
|
-
if(err){ dfd.reject(err); }
|
|
846
|
-
else {
|
|
847
|
-
// Passed all validations, Constructing URL
|
|
848
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] + self.config.ANALYTICS_API_URLS.getClassRecordItemAggregations;
|
|
849
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
850
|
-
|
|
851
|
-
// Setup Query Params
|
|
852
|
-
var queryParams = {
|
|
853
|
-
classid: options.classid,
|
|
854
|
-
productcode: options.productcode,
|
|
855
|
-
'item-code': options['item-code']
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
// Setup Request with url and params
|
|
859
|
-
var requestAPI = request.get(url).query(queryParams);
|
|
860
|
-
// Setup token in Authorization Header
|
|
861
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
862
|
-
|
|
863
|
-
// setting up traceid
|
|
864
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
865
|
-
|
|
866
|
-
// Call GET GET CLASS RECORD ITEM
|
|
867
|
-
requestAPI.end(function(error, response) {
|
|
868
|
-
if(error) {
|
|
869
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
870
|
-
dfd.reject(err);
|
|
871
|
-
} else {
|
|
872
|
-
dfd.resolve(response.body)
|
|
873
|
-
}
|
|
874
|
-
});
|
|
875
|
-
}
|
|
876
|
-
} else {
|
|
877
|
-
err.message = err.description = 'Required parameter classid or ' +
|
|
878
|
-
'productcode not found in request options.';
|
|
879
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
880
|
-
dfd.reject(err);
|
|
881
|
-
}
|
|
882
|
-
return dfd.promise;
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
/*options = {
|
|
886
|
-
* classid: 'string', // class uuid(mandatory)
|
|
887
|
-
* productcode: 'string', // product code(optional)
|
|
888
|
-
* 'item-code': 'string', // itemcode of item(optional)
|
|
889
|
-
* groupid: 'string', // groupid of a group(optional)
|
|
890
|
-
* id: 'string' // id of showcase record item(optional)
|
|
891
|
-
*}
|
|
892
|
-
*/
|
|
893
|
-
function getShowcaseRecordOfAClass(options) {
|
|
894
|
-
var self = this;
|
|
895
|
-
|
|
896
|
-
//Initializing DFD
|
|
897
|
-
var dfd = q.defer(), err = {};
|
|
898
|
-
|
|
899
|
-
// Validations
|
|
900
|
-
if(options && options.classid) {
|
|
901
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
902
|
-
if(err){ dfd.reject(err); }
|
|
903
|
-
else {
|
|
904
|
-
// Passed all validations, Constructing URL
|
|
905
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] + self.config.ANALYTICS_API_URLS.getShowcaseRecordOfAClass;
|
|
906
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
907
|
-
|
|
908
|
-
// Setup Query Params
|
|
909
|
-
var queryParams = {
|
|
910
|
-
classid: options.classid
|
|
911
|
-
};
|
|
912
|
-
|
|
913
|
-
if(options.productcode) { queryParams.productcode = options.productcode; }
|
|
914
|
-
if(options.groupid) { queryParams.groupid = options.groupid; }
|
|
915
|
-
if(options['item-code']) { queryParams['item-code'] = options['item-code']; }
|
|
916
|
-
if(options.id) { queryParams.id = options.id; }
|
|
917
|
-
|
|
918
|
-
// Setup Request with url and params
|
|
919
|
-
var requestAPI = request.get(url).query(queryParams);
|
|
920
|
-
// Setup token in Authorization Header
|
|
921
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
922
|
-
|
|
923
|
-
// setting up traceid
|
|
924
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
925
|
-
|
|
926
|
-
// Call GET GET CLASS RECORD ITEM
|
|
927
|
-
requestAPI.end(function(error, response) {
|
|
928
|
-
if(error) {
|
|
929
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
930
|
-
dfd.reject(err);
|
|
931
|
-
} else {
|
|
932
|
-
dfd.resolve(response.body);
|
|
933
|
-
}
|
|
934
|
-
});
|
|
935
|
-
}
|
|
936
|
-
} else {
|
|
937
|
-
err.message = err.description = 'Required parameter classid not found in request options.';
|
|
938
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
939
|
-
dfd.reject(err);
|
|
940
|
-
}
|
|
941
|
-
return dfd.promise;
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
/**
|
|
945
|
-
* options = {
|
|
946
|
-
* classid: 'string', // mandatory, class uuid
|
|
947
|
-
* productcode: 'string', // mandatory, product code
|
|
948
|
-
* groupid: 'string', // mandatory, group id
|
|
949
|
-
* itemcode: 'string', // optional, item code of the group LO whose GR is required
|
|
950
|
-
* history: boolean // optional, if true give all the submissions else give only the latest submission
|
|
951
|
-
* }
|
|
952
|
-
*/
|
|
953
|
-
function getGroupRecord(options) {
|
|
954
|
-
var self = this;
|
|
955
|
-
|
|
956
|
-
//Initializing DFD
|
|
957
|
-
var dfd = q.defer(), err = {};
|
|
958
|
-
|
|
959
|
-
// Validations
|
|
960
|
-
if(options && options.classid && options.productcode && options.groupid) {
|
|
961
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
962
|
-
if(err){ dfd.reject(err); }
|
|
963
|
-
else {
|
|
964
|
-
// Passed all validations, Constructing URL
|
|
965
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] + self.config.ANALYTICS_API_URLS.getGroupRecord;
|
|
966
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
967
|
-
|
|
968
|
-
// Setup Query Params
|
|
969
|
-
var queryParams = {
|
|
970
|
-
classid: options.classid,
|
|
971
|
-
productcode: options.productcode,
|
|
972
|
-
groupid: options.groupid
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
if(options.itemcode) { queryParams.itemcode = options.itemcode; }
|
|
976
|
-
if(options.history) { queryParams.history = options.history; }
|
|
977
|
-
|
|
978
|
-
// Setup Request with url and params
|
|
979
|
-
var requestAPI = request.get(url).query(queryParams);
|
|
980
|
-
// Setup token in Authorization Header
|
|
981
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
982
|
-
|
|
983
|
-
// setting up traceid
|
|
984
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
985
|
-
|
|
986
|
-
// Call GET GET GROUP RECORD ITEM
|
|
987
|
-
requestAPI.end(function(error, response) {
|
|
988
|
-
if(error) {
|
|
989
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
990
|
-
dfd.reject(err);
|
|
991
|
-
} else {
|
|
992
|
-
dfd.resolve(response.body)
|
|
993
|
-
}
|
|
994
|
-
});
|
|
995
|
-
}
|
|
996
|
-
} else {
|
|
997
|
-
err.message = err.description = 'Required parameter classid or ' +
|
|
998
|
-
'productcode or groupid not found in request options.';
|
|
999
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1000
|
-
dfd.reject(err);
|
|
1001
|
-
}
|
|
1002
|
-
return dfd.promise;
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
/**
|
|
1006
|
-
* This function returns the recent pending submissions of all the groups in a Class for a Product.
|
|
1007
|
-
* options = {
|
|
1008
|
-
* classid: string,
|
|
1009
|
-
* productcode: string,
|
|
1010
|
-
* details: boolean, // optional, if details of submissions is also required.
|
|
1011
|
-
* limit: number // optional, number of submissions to be fetched at once (default & max is 100)
|
|
1012
|
-
* }
|
|
1013
|
-
*/
|
|
1014
|
-
function getClassGroupsRecentPendingSubmissions(options) {
|
|
1015
|
-
var self = this;
|
|
1016
|
-
var dfd = q.defer(), err = {};
|
|
1017
|
-
|
|
1018
|
-
if(options && options.classid && options.productcode) {
|
|
1019
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1020
|
-
if(err) { dfd.reject(err); }
|
|
1021
|
-
else {
|
|
1022
|
-
// Passed all validations, Constructing URL
|
|
1023
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
1024
|
-
self.config.ANALYTICS_API_URLS.getClassGroupsRecentPendingSubmissions;
|
|
1025
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1026
|
-
|
|
1027
|
-
// Setup Query Params
|
|
1028
|
-
var queryParams = {
|
|
1029
|
-
classid: options.classid,
|
|
1030
|
-
productcode: options.productcode
|
|
1031
|
-
};
|
|
1032
|
-
|
|
1033
|
-
if(options.details) { queryParams.details = options.details; }
|
|
1034
|
-
if(options.limit) { queryParams.limit = options.limit; }
|
|
1035
|
-
|
|
1036
|
-
// Setup Request with url and params
|
|
1037
|
-
var requestAPI = request.get(url).query(queryParams);
|
|
1038
|
-
// Setup token in Authorization Header
|
|
1039
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1040
|
-
|
|
1041
|
-
// setting up traceid
|
|
1042
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1043
|
-
|
|
1044
|
-
// Call GET Class Product Recent Pending Submissions of all groups
|
|
1045
|
-
requestAPI.end(function(error, response) {
|
|
1046
|
-
if(error) {
|
|
1047
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1048
|
-
dfd.reject(err);
|
|
1049
|
-
} else {
|
|
1050
|
-
dfd.resolve(response.body);
|
|
1051
|
-
}
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
else {
|
|
1056
|
-
err.message = err.description = 'Mandatory parameters ["classid", "productcode"] not found in ' +
|
|
1057
|
-
'request options.';
|
|
1058
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1059
|
-
dfd.reject(err);
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
return dfd.promise;
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
/**
|
|
1066
|
-
* options = {
|
|
1067
|
-
* classid: 'string', //mandatory
|
|
1068
|
-
* productcode: 'string' //mandatory
|
|
1069
|
-
*}
|
|
1070
|
-
*/
|
|
1071
|
-
function getGroupsWithEvaluatedOnce(options) {
|
|
1072
|
-
var self = this, err = {};
|
|
1073
|
-
//Initializing promise
|
|
1074
|
-
var dfd = q.defer();
|
|
1075
|
-
if(options && options.classid && options.productcode) {
|
|
1076
|
-
//Validations
|
|
1077
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1078
|
-
if(err) { dfd.reject(err); }
|
|
1079
|
-
else {
|
|
1080
|
-
// Passed all validations, Construct API url
|
|
1081
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
1082
|
-
self.config.ANALYTICS_API_URLS.getGroupsWithEvaluatedOnce;
|
|
1083
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1084
|
-
|
|
1085
|
-
// Setup params
|
|
1086
|
-
var params = {
|
|
1087
|
-
classid: options.classid,
|
|
1088
|
-
productcode: options.productcode
|
|
1089
|
-
};
|
|
1090
|
-
// Setup request with URL and Params
|
|
1091
|
-
var requestAPI = request.get(url).query(params);
|
|
1092
|
-
// Setup token in Authorization header
|
|
1093
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1094
|
-
|
|
1095
|
-
// setting up traceid
|
|
1096
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1097
|
-
|
|
1098
|
-
requestAPI.end(function(error, response) {
|
|
1099
|
-
if(error) {
|
|
1100
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1101
|
-
dfd.reject(err);
|
|
1102
|
-
}
|
|
1103
|
-
else { dfd.resolve(response.body); }
|
|
1104
|
-
});
|
|
1105
|
-
}
|
|
1106
|
-
} else {
|
|
1107
|
-
err.message = err.description = 'Required parameter classid or ' +
|
|
1108
|
-
'productcode not found in request options.';
|
|
1109
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1110
|
-
dfd.reject(err);
|
|
1111
|
-
}
|
|
1112
|
-
return dfd.promise;
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
//options = {
|
|
1116
|
-
// classid: 'string',
|
|
1117
|
-
// productcode: 'string',
|
|
1118
|
-
// userid: 'string' //optional
|
|
1119
|
-
//}
|
|
1120
|
-
|
|
1121
|
-
function getClassRecordUserAggregations(options) {
|
|
1122
|
-
var self = this, err = {};
|
|
1123
|
-
//Initializing promise
|
|
1124
|
-
var dfd = q.defer();
|
|
1125
|
-
if(options && options.classid && options.productcode) {
|
|
1126
|
-
//Validations
|
|
1127
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1128
|
-
if(err) { dfd.reject(err); }
|
|
1129
|
-
else {
|
|
1130
|
-
// Passed all validations, Construct API url
|
|
1131
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
1132
|
-
self.config.ANALYTICS_API_URLS.getClassRecordUserAggregations;
|
|
1133
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1134
|
-
|
|
1135
|
-
// Setup params
|
|
1136
|
-
var params = {
|
|
1137
|
-
classid: options.classid,
|
|
1138
|
-
productcode: options.productcode,
|
|
1139
|
-
userid: options.userid
|
|
1140
|
-
};
|
|
1141
|
-
// Setup request with URL and Params
|
|
1142
|
-
var requestAPI = request.get(url).query(params);
|
|
1143
|
-
// Setup token in Authorization header
|
|
1144
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1145
|
-
|
|
1146
|
-
// setting up traceid
|
|
1147
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1148
|
-
|
|
1149
|
-
requestAPI.end(function(error, response) {
|
|
1150
|
-
if(error) {
|
|
1151
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1152
|
-
dfd.reject(err);
|
|
1153
|
-
}
|
|
1154
|
-
else { dfd.resolve(response.body); }
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1157
|
-
} else {
|
|
1158
|
-
err.message = err.description = 'Required parameter classid or ' +
|
|
1159
|
-
'productcode not found in request options.';
|
|
1160
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1161
|
-
dfd.reject(err);
|
|
1162
|
-
}
|
|
1163
|
-
return dfd.promise;
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
//options = {
|
|
1167
|
-
// type: ['stat' / 'timeseries'],
|
|
1168
|
-
// analyticsDataType: ['enrolments' / 'logins']
|
|
1169
|
-
// classid: 'string',
|
|
1170
|
-
// range: '', // for type - stat // OPTIONAL
|
|
1171
|
-
// start: '', // time(ms) - start interval // OPTIONAL
|
|
1172
|
-
// end: '' // time(ms) - end interval // OPTIONAL
|
|
1173
|
-
// interval: '' The interval at which counters are displayed. Possible values are five_minutes, half_hour, hour, six_day, day, week, and month. Default interval is day. // Only for type - timeseries // OPTIONAL
|
|
1174
|
-
//}
|
|
1175
|
-
function getClassAnalytics(options) {
|
|
1176
|
-
var self = this;
|
|
1177
|
-
|
|
1178
|
-
//Initializing promise
|
|
1179
|
-
var dfd = q.defer();
|
|
1180
|
-
//Validations
|
|
1181
|
-
var err = {};
|
|
1182
|
-
if(options && options.type && options.analyticsDataType && options.classid) {
|
|
1183
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1184
|
-
if(err) { dfd.reject(err); }
|
|
1185
|
-
else {
|
|
1186
|
-
err = {};
|
|
1187
|
-
if((!options.range && !options.interval) ||
|
|
1188
|
-
(options.range && options.type === 'stat') ||
|
|
1189
|
-
(options.interval && options.type === 'timeseries'))
|
|
1190
|
-
{
|
|
1191
|
-
var allowedAnalyticsDataType = ['enrolments', 'logins'];
|
|
1192
|
-
if(allowedAnalyticsDataType.indexOf(options.analyticsDataType) > -1) {
|
|
1193
|
-
//Passed all validations, Construct API url
|
|
1194
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
1195
|
-
self.config.ANALYTICS_API_URLS.getClassAnalytics;
|
|
1196
|
-
url = helpers.api.constructAPIUrl(url, {
|
|
1197
|
-
orgId: self.orgId, type: options.type,
|
|
1198
|
-
analyticsDataType: options.analyticsDataType
|
|
1199
|
-
});
|
|
1200
|
-
|
|
1201
|
-
var params = { classid: options.classid };
|
|
1202
|
-
if(options) {
|
|
1203
|
-
if(options.range) { params.range = options.range; }
|
|
1204
|
-
if(options.start) { params.start = options.start; }
|
|
1205
|
-
if(options.end) { params.end = options.end; }
|
|
1206
|
-
if(options.interval) { params.interval = options.interval; }
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
//Setup request with URL and Params
|
|
1210
|
-
var requestAPI = request.get(url).query(params);
|
|
1211
|
-
|
|
1212
|
-
//Setup token in Authorization header
|
|
1213
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1214
|
-
|
|
1215
|
-
// setting up traceid
|
|
1216
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1217
|
-
|
|
1218
|
-
//Call Product Timespent Api
|
|
1219
|
-
requestAPI.end(function(err, response) {
|
|
1220
|
-
if(err) {
|
|
1221
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
1222
|
-
dfd.reject(err);
|
|
1223
|
-
}
|
|
1224
|
-
else { dfd.resolve(response.body); }
|
|
1225
|
-
});
|
|
1226
|
-
} else {
|
|
1227
|
-
err.message = err.description = 'analyticsDataType: ' +
|
|
1228
|
-
options.analyticsDataType + ' is not supported';
|
|
1229
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1230
|
-
dfd.reject(err);
|
|
1231
|
-
}
|
|
1232
|
-
} else {
|
|
1233
|
-
err.message = err.description = 'Range should be defined for type - ' +
|
|
1234
|
-
'"stat" and Interval should be defined for type - "timeseries"';
|
|
1235
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1236
|
-
dfd.reject(err);
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
} else {
|
|
1240
|
-
err.message = err.description = 'Required options ["type", "analyticsDataType",' +
|
|
1241
|
-
' "classid"] not found in request options';
|
|
1242
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1243
|
-
dfd.reject(err);
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
return dfd.promise;
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
//options = {
|
|
1250
|
-
// useranalyticid: <userid>,
|
|
1251
|
-
// cursor: '', // OPTIONAL cursor to next set of documents
|
|
1252
|
-
// limit: '' // OPTIONAL limit of documents per function call (Default is 5)
|
|
1253
|
-
//}
|
|
1254
|
-
function getArchivedUserAnalytics(options) {
|
|
1255
|
-
var self = this;
|
|
1256
|
-
|
|
1257
|
-
//Initializing promise
|
|
1258
|
-
var dfd = q.defer();
|
|
1259
|
-
//Validations
|
|
1260
|
-
var err = {};
|
|
1261
|
-
if(options && options.useranalyticid) {
|
|
1262
|
-
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1263
|
-
if(err) { dfd.reject(err); }
|
|
1264
|
-
else {
|
|
1265
|
-
//Passed all validations, Construct API url
|
|
1266
|
-
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
1267
|
-
self.config.ANALYTICS_API_URLS.getArchivedUserAnalytics;
|
|
1268
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1269
|
-
var params = { useranalyticid: options.useranalyticid };
|
|
1270
|
-
if(options) {
|
|
1271
|
-
if(options.cursor) { params.cursor = options.cursor; }
|
|
1272
|
-
if(options.limit) { params.limit = options.limit; }
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
//Setup request with URL and Params
|
|
1276
|
-
var requestAPI = request.get(url).query(params);
|
|
1277
|
-
|
|
1278
|
-
//Setup token in Authorization header
|
|
1279
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1280
|
-
|
|
1281
|
-
// setting up traceid
|
|
1282
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1283
|
-
|
|
1284
|
-
//Call Product Timespent Api
|
|
1285
|
-
requestAPI.end(function(err, response) {
|
|
1286
|
-
if(err) {
|
|
1287
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
1288
|
-
dfd.reject(err);
|
|
1289
|
-
}
|
|
1290
|
-
else { dfd.resolve(response.body); }
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
|
-
} else {
|
|
1294
|
-
err.message = err.description = "Mandatory field 'useranalyticid' not found" +
|
|
1295
|
-
" in request options";
|
|
1296
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1297
|
-
dfd.reject(err);
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
return dfd.promise;
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
/*********************************************************
|
|
1304
|
-
* This function converts the data from questions format to
|
|
1305
|
-
* Learning Objective Format.
|
|
1306
|
-
*********************************************************/
|
|
1307
|
-
function getQuestionProgressByLearningObjective(questionsArray) {
|
|
1308
|
-
var learningObjectiveFormat = {};
|
|
1309
|
-
for(var i = 0; i < questionsArray.length; i++) {
|
|
1310
|
-
var questionLearningObjectives = questionsArray[i]['learning-objectives'];
|
|
1311
|
-
for(var j = 0; j < questionLearningObjectives.length; j++) {
|
|
1312
|
-
var analytics;
|
|
1313
|
-
var correct;
|
|
1314
|
-
var questionDataMap;
|
|
1315
|
-
if(!learningObjectiveFormat[questionLearningObjectives[j]]) {
|
|
1316
|
-
correct = 0;
|
|
1317
|
-
analytics = questionsArray[i].__analytics;
|
|
1318
|
-
if(analytics.statusEvaluation === 'correct') {
|
|
1319
|
-
correct++;
|
|
1320
|
-
}
|
|
1321
|
-
var questionsMap = {
|
|
1322
|
-
'status': {
|
|
1323
|
-
'correct': correct,
|
|
1324
|
-
'total': 1
|
|
1325
|
-
},
|
|
1326
|
-
'questions': []
|
|
1327
|
-
};
|
|
1328
|
-
questionDataMap = {
|
|
1329
|
-
'question-code': questionsArray[i].questionCode,
|
|
1330
|
-
'analytics': analytics
|
|
1331
|
-
};
|
|
1332
|
-
questionsMap.questions.push(questionDataMap);
|
|
1333
|
-
learningObjectiveFormat[questionLearningObjectives[j]] = questionsMap;
|
|
1334
|
-
}
|
|
1335
|
-
else {
|
|
1336
|
-
var savedQuestionsMap = learningObjectiveFormat[questionLearningObjectives[j]];
|
|
1337
|
-
analytics = questionsArray[i].__analytics;
|
|
1338
|
-
if(analytics.statusEvaluation === 'correct') {
|
|
1339
|
-
correct = savedQuestionsMap.status.correct;
|
|
1340
|
-
savedQuestionsMap.status.correct = correct + 1;
|
|
1341
|
-
}
|
|
1342
|
-
var total = savedQuestionsMap.status.total;
|
|
1343
|
-
savedQuestionsMap.status.total = total + 1;
|
|
1344
|
-
questionDataMap = {
|
|
1345
|
-
'question-code': questionsArray[i].questionCode,
|
|
1346
|
-
'analytics': analytics
|
|
1347
|
-
};
|
|
1348
|
-
savedQuestionsMap.questions.push(questionDataMap);
|
|
1349
|
-
learningObjectiveFormat[questionLearningObjectives[j]] = savedQuestionsMap;
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
return learningObjectiveFormat;
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
/* options = {
|
|
1357
|
-
"classid": "string", // required
|
|
1358
|
-
};
|
|
1359
|
-
*/
|
|
1360
|
-
function getAllAssignedPathsOfClass(options) {
|
|
1361
|
-
var self = this;
|
|
1362
|
-
// Initializing promise
|
|
1363
|
-
var dfd = q.defer();
|
|
1364
|
-
var err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1365
|
-
if(err) { dfd.reject(err); }
|
|
1366
|
-
else {
|
|
1367
|
-
if(options && options.classid) {
|
|
1368
|
-
|
|
1369
|
-
// Passed all validations, Contruct API url
|
|
1370
|
-
var url = self.config.DEFAULT_HOSTS.ANALYTICS + self.config.ANALYTICS_API_URLS.getAllAssignedPathsOfClass;
|
|
1371
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1372
|
-
|
|
1373
|
-
var queryParams = { classid: options.classid };
|
|
1374
|
-
|
|
1375
|
-
// Setup request with URL and Params
|
|
1376
|
-
var requestAPI = request.get(url).query(queryParams);
|
|
1377
|
-
|
|
1378
|
-
//Setup token in Authorization header
|
|
1379
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1380
|
-
|
|
1381
|
-
// setting up traceid
|
|
1382
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1383
|
-
|
|
1384
|
-
requestAPI.end(function (error, response) {
|
|
1385
|
-
if(error) {
|
|
1386
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1387
|
-
dfd.reject(err);
|
|
1388
|
-
}
|
|
1389
|
-
else { dfd.resolve(response.body); }
|
|
1390
|
-
});
|
|
1391
|
-
}
|
|
1392
|
-
else {
|
|
1393
|
-
err = {};
|
|
1394
|
-
err.message = err.description = 'Mandatory param - classid not found in request options.';
|
|
1395
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1396
|
-
dfd.reject(err);
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
return dfd.promise;
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
/* options = {
|
|
1403
|
-
"classid": "string", // required
|
|
1404
|
-
"assignedPathId" : "string", // required
|
|
1405
|
-
"productcode" : "string" //required
|
|
1406
|
-
};
|
|
1407
|
-
*/
|
|
1408
|
-
function getAssignedPathAnalytics(options) {
|
|
1409
|
-
var self = this;
|
|
1410
|
-
// Initializing promise
|
|
1411
|
-
var dfd = q.defer();
|
|
1412
|
-
var err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1413
|
-
if(err) { dfd.reject(err); }
|
|
1414
|
-
else {
|
|
1415
|
-
if(options && options.classid && options.assignedPathId && options.productcode) {
|
|
1416
|
-
// Passed all validations, Contruct API url
|
|
1417
|
-
var url = self.config.DEFAULT_HOSTS.ANALYTICS + self.config.ANALYTICS_API_URLS.getAssignedPathAnalytics;
|
|
1418
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1419
|
-
|
|
1420
|
-
var queryParams = {
|
|
1421
|
-
classid: options.classid,
|
|
1422
|
-
assignedpathid: options.assignedPathId,
|
|
1423
|
-
productcode: options.productcode
|
|
1424
|
-
};
|
|
1425
|
-
// Setup request with URL and Params
|
|
1426
|
-
var requestAPI = request.get(url).query(queryParams);
|
|
1427
|
-
|
|
1428
|
-
//Setup token in Authorization header
|
|
1429
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1430
|
-
|
|
1431
|
-
// setting up traceid
|
|
1432
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1433
|
-
|
|
1434
|
-
requestAPI.end(function (error, response) {
|
|
1435
|
-
if(error) {
|
|
1436
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1437
|
-
dfd.reject(err);
|
|
1438
|
-
}
|
|
1439
|
-
else { dfd.resolve(response.body); }
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
else {
|
|
1443
|
-
err = {};
|
|
1444
|
-
err.message = err.description = 'Mandatory params - classid or assignedPathId or productcode not found in request options.';
|
|
1445
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1446
|
-
dfd.reject(err);
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
return dfd.promise;
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
/* options = {
|
|
1453
|
-
"classid": "string", // required
|
|
1454
|
-
"userid" : "string", // required
|
|
1455
|
-
"progress" : "true/false",
|
|
1456
|
-
"group" : "true/false"
|
|
1457
|
-
};
|
|
1458
|
-
*/
|
|
1459
|
-
function getMyAssignedPathsOfClass(options) {
|
|
1460
|
-
var self = this;
|
|
1461
|
-
// Initializing promise
|
|
1462
|
-
var dfd = q.defer();
|
|
1463
|
-
var err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1464
|
-
if(err) { dfd.reject(err); }
|
|
1465
|
-
else {
|
|
1466
|
-
if(options && options.classid && options.userid ) {
|
|
1467
|
-
|
|
1468
|
-
// Passed all validations, Contruct API url
|
|
1469
|
-
var url = self.config.DEFAULT_HOSTS.ANALYTICS + self.config.ANALYTICS_API_URLS.getMyAssignedPathsOfClass;
|
|
1470
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1471
|
-
var queryParams = { userid: options.userid, classid: options.classid };
|
|
1472
|
-
if(options.progress) { queryParams.progress = options.progress; }
|
|
1473
|
-
if(options.group) { queryParams.group = options.group; }
|
|
1474
|
-
|
|
1475
|
-
// Setup request with URL and Params
|
|
1476
|
-
var requestAPI = request.get(url).query(queryParams);
|
|
1477
|
-
//Setup token in Authorization header
|
|
1478
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1479
|
-
|
|
1480
|
-
// setting up traceid
|
|
1481
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1482
|
-
|
|
1483
|
-
requestAPI.end(function (error, response) {
|
|
1484
|
-
if(error) {
|
|
1485
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1486
|
-
dfd.reject(err);
|
|
1487
|
-
}
|
|
1488
|
-
else { dfd.resolve(response.body); }
|
|
1489
|
-
});
|
|
1490
|
-
}
|
|
1491
|
-
else {
|
|
1492
|
-
err = {};
|
|
1493
|
-
err.message = err.description = 'Mandatory params - classid, userid not found in ' +
|
|
1494
|
-
'request options.';
|
|
1495
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1496
|
-
dfd.reject(err);
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
return dfd.promise;
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
/* options = {
|
|
1503
|
-
"classid": "string", // required
|
|
1504
|
-
"userid" : "string", // required
|
|
1505
|
-
"assignedPathId" : "string", // required
|
|
1506
|
-
"progress" : "true/false",
|
|
1507
|
-
"group" : "true/false"
|
|
1508
|
-
};
|
|
1509
|
-
*/
|
|
1510
|
-
function getMyParticularAssignedPathOfClass(options) {
|
|
1511
|
-
var self = this;
|
|
1512
|
-
// Initializing promise
|
|
1513
|
-
var dfd = q.defer();
|
|
1514
|
-
var err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1515
|
-
if(err) { dfd.reject(err); }
|
|
1516
|
-
else {
|
|
1517
|
-
if(options && options.classid && options.userid && options.assignedPathId ) {
|
|
1518
|
-
|
|
1519
|
-
// Passed all validations, Contruct API url
|
|
1520
|
-
var url = self.config.DEFAULT_HOSTS.ANALYTICS + self.config.ANALYTICS_API_URLS.getMyAssignedPathsOfClass;
|
|
1521
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1522
|
-
|
|
1523
|
-
var queryParams = {
|
|
1524
|
-
assignedpathid: options.assignedPathId, classid: options.classid, userid: options.userid
|
|
1525
|
-
};
|
|
1526
|
-
|
|
1527
|
-
if(options.progress) { queryParams.progress = options.progress; }
|
|
1528
|
-
if(options.group) { queryParams.group = options.group; }
|
|
1529
|
-
|
|
1530
|
-
// Setup request with URL and Params
|
|
1531
|
-
var requestAPI = request.get(url).query(queryParams);
|
|
1532
|
-
//Setup token in Authorization header
|
|
1533
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1534
|
-
|
|
1535
|
-
// setting up traceid
|
|
1536
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1537
|
-
|
|
1538
|
-
requestAPI.end(function (error, response) {
|
|
1539
|
-
if(error) {
|
|
1540
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1541
|
-
dfd.reject(err);
|
|
1542
|
-
}
|
|
1543
|
-
else { dfd.resolve(response.body); }
|
|
1544
|
-
});
|
|
1545
|
-
}
|
|
1546
|
-
else {
|
|
1547
|
-
err = {};
|
|
1548
|
-
err.message = err.description = 'Mandatory params - classid, userid, assignedPathId not found in ' +
|
|
1549
|
-
'request options.';
|
|
1550
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1551
|
-
dfd.reject(err);
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
return dfd.promise;
|
|
1555
|
-
}
|
|
1
|
+
/*************************************************************************
|
|
2
|
+
*
|
|
3
|
+
* COMPRO CONFIDENTIAL
|
|
4
|
+
* __________________
|
|
5
|
+
*
|
|
6
|
+
* [2015] - [2020] Compro Technologies Private Limited
|
|
7
|
+
* All Rights Reserved.
|
|
8
|
+
*
|
|
9
|
+
* NOTICE: All information contained herein is, and remains
|
|
10
|
+
* the property of Compro Technologies Private Limited. The
|
|
11
|
+
* intellectual and technical concepts contained herein are
|
|
12
|
+
* proprietary to Compro Technologies Private Limited and may
|
|
13
|
+
* be covered by U.S. and Foreign Patents, patents in process,
|
|
14
|
+
* and are protected by trade secret or copyright law.
|
|
15
|
+
*
|
|
16
|
+
* Dissemination of this information or reproduction of this material
|
|
17
|
+
* is strictly forbidden unless prior written permission is obtained
|
|
18
|
+
* from Compro Technologies Pvt. Ltd..
|
|
19
|
+
***************************************************************************/
|
|
20
|
+
|
|
21
|
+
/***********************************************************
|
|
22
|
+
* comproDLS SDK Analytics API Adaptor
|
|
23
|
+
* Functions for calling Analytics API.
|
|
24
|
+
************************************************************/
|
|
25
|
+
|
|
26
|
+
/*********************************
|
|
27
|
+
* Setting Up Module Entry Point
|
|
28
|
+
**********************************/
|
|
29
|
+
|
|
30
|
+
var q = require('q');
|
|
31
|
+
var request = require('superagent');
|
|
32
|
+
|
|
33
|
+
var helpers = require('../../helpers');
|
|
34
|
+
var DLSError = helpers.errors.DLSError;
|
|
35
|
+
|
|
36
|
+
module.exports = analytics;
|
|
37
|
+
|
|
38
|
+
/*********************************
|
|
39
|
+
* Public Function definitions
|
|
40
|
+
**********************************/
|
|
41
|
+
function analytics() {
|
|
42
|
+
return {
|
|
43
|
+
archiveUserAnalytics: archiveUserAnalytics.bind(this),
|
|
44
|
+
getArchivedUserAnalytics: getArchivedUserAnalytics.bind(this),
|
|
45
|
+
|
|
46
|
+
getOrgAnalyticsStat: getOrgAnalyticsStat.bind(this),
|
|
47
|
+
|
|
48
|
+
getClassAnalytics: getClassAnalytics.bind(this),
|
|
49
|
+
getClassProductRecentPendingSubmissions: getClassProductRecentPendingSubmissions.bind(this),
|
|
50
|
+
getClassRecordUserAggregations: getClassRecordUserAggregations.bind(this),
|
|
51
|
+
getClassRecord: getClassRecord.bind(this),
|
|
52
|
+
getClassRecordItemAggregations: getClassRecordItemAggregations.bind(this),
|
|
53
|
+
getShowcaseRecordOfAClass: getShowcaseRecordOfAClass.bind(this),
|
|
54
|
+
|
|
55
|
+
getGroupRecord: getGroupRecord.bind(this),
|
|
56
|
+
getClassGroupsRecentPendingSubmissions: getClassGroupsRecentPendingSubmissions.bind(this),
|
|
57
|
+
getGroupsWithEvaluatedOnce: getGroupsWithEvaluatedOnce.bind(this),
|
|
58
|
+
|
|
59
|
+
getUserProductAnalytics: getUserProductAnalytics.bind(this),
|
|
60
|
+
getUserProductAnalyticById: getUserProductAnalyticById.bind(this),
|
|
61
|
+
getExternalDataForUserAnalyticItem: getExternalDataForUserAnalyticItem.bind(this),
|
|
62
|
+
searchUserProductAnalytics: searchUserProductAnalytics.bind(this),
|
|
63
|
+
getUserClassRecentSubmissions: getUserClassRecentSubmissions.bind(this),
|
|
64
|
+
getStudentsWithEvaluatedOnce: getStudentsWithEvaluatedOnce.bind(this),
|
|
65
|
+
|
|
66
|
+
getAppState: getAppState.bind(this),
|
|
67
|
+
updateAppState: updateAppState.bind(this),
|
|
68
|
+
deleteAppState: deleteAppState.bind(this),
|
|
69
|
+
|
|
70
|
+
getQuestionProgressByLearningObjective: getQuestionProgressByLearningObjective.bind(this),
|
|
71
|
+
|
|
72
|
+
//AssignedPaths Related APIs
|
|
73
|
+
getAllAssignedPathsOfClass: getAllAssignedPathsOfClass.bind(this),
|
|
74
|
+
getMyAssignedPathsOfClass: getMyAssignedPathsOfClass.bind(this),
|
|
75
|
+
getAssignedPathAnalytics: getAssignedPathAnalytics.bind(this),
|
|
76
|
+
getMyParticularAssignedPathOfClass: getMyParticularAssignedPathOfClass.bind(this)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//options = {
|
|
81
|
+
// type: 'users/classes', // choose any one
|
|
82
|
+
// range: '', //
|
|
83
|
+
// start: '', // time(ms) - start interval
|
|
84
|
+
// end: '', // time(ms) - end interval
|
|
85
|
+
// role: '', // The role of users i.e. student, teacher, etc. No default role (i.e. all users).
|
|
86
|
+
// shadow: <boolean> // if user/class is shadow-provsioined.
|
|
87
|
+
//}
|
|
88
|
+
function getOrgAnalyticsStat(options) {
|
|
89
|
+
var self = this;
|
|
90
|
+
|
|
91
|
+
//Initializing promise
|
|
92
|
+
var dfd = q.defer();
|
|
93
|
+
//Validations
|
|
94
|
+
var err = {};
|
|
95
|
+
if(options && options.type) {
|
|
96
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
97
|
+
if(err) { dfd.reject(err); }
|
|
98
|
+
else {
|
|
99
|
+
err = {};
|
|
100
|
+
var allowedAnalyticsDataType = ['users', 'classes'];
|
|
101
|
+
if(allowedAnalyticsDataType.indexOf(options.type) > -1) {
|
|
102
|
+
//Passed all validations, Construct API url
|
|
103
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
104
|
+
self.config.ANALYTICS_API_URLS.getOrgAnalyticsStat;
|
|
105
|
+
url = helpers.api.constructAPIUrl(url, {
|
|
106
|
+
orgId: self.orgId, type: options.type
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
var params = {};
|
|
110
|
+
if(options) {
|
|
111
|
+
if(options.range) { params.range = options.range; }
|
|
112
|
+
if(options.start) { params.start = options.start; }
|
|
113
|
+
if(options.end) { params.end = options.end; }
|
|
114
|
+
if(options.role) { params.role = options.role; }
|
|
115
|
+
if(options.shadow) { params.shadow = options.shadow; }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//Setup request with URL and Params
|
|
119
|
+
var requestAPI = request.get(url).query(params);
|
|
120
|
+
|
|
121
|
+
//Setup token in Authorization header
|
|
122
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
123
|
+
|
|
124
|
+
// setting up traceid
|
|
125
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
126
|
+
|
|
127
|
+
//Call Product Timespent Api
|
|
128
|
+
requestAPI.end(function(err, response) {
|
|
129
|
+
if(err) {
|
|
130
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
131
|
+
dfd.reject(err);
|
|
132
|
+
}
|
|
133
|
+
else { dfd.resolve(response.body); }
|
|
134
|
+
});
|
|
135
|
+
} else {
|
|
136
|
+
err.message = err.description = 'Type: ' + options.type + ' is not supported';
|
|
137
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
138
|
+
dfd.reject(err);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
err.message = err.description = 'type not found in request options';
|
|
143
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
144
|
+
dfd.reject(err);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return dfd.promise;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//options = {
|
|
151
|
+
// type: 'string', // [items/summary]
|
|
152
|
+
// userid: 'string', // user uuid
|
|
153
|
+
// productcode: 'string, // product code
|
|
154
|
+
// classid: 'string', // OPTIONAL
|
|
155
|
+
// itemcode: 'string', // OPTIONAL (only for 'type=items') item-code of the required item
|
|
156
|
+
// metrics: boolean // OPTIONAL (only for 'type=items') true/false - aggregations on the
|
|
157
|
+
// item(s), default - true
|
|
158
|
+
// history: boolean // If history is true - submission is array else submission is object
|
|
159
|
+
// expiredView: boolean // If expiredView is true - items from class record matrix will be returned.
|
|
160
|
+
// externalData: boolean // OPTIONAL(default is 'false' - only works with itemcode) whether to return external
|
|
161
|
+
//secondary evaluation data or not.
|
|
162
|
+
// group: boolean // If group is true - then it will return group data from P1.
|
|
163
|
+
//}
|
|
164
|
+
function getUserProductAnalytics(options) {
|
|
165
|
+
var self = this;
|
|
166
|
+
|
|
167
|
+
//Initializing promise
|
|
168
|
+
var dfd = q.defer();
|
|
169
|
+
//Validations
|
|
170
|
+
var err = {};
|
|
171
|
+
if(options && options.type && options.userid && options.productcode) {
|
|
172
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
173
|
+
if(err) { dfd.reject(err); }
|
|
174
|
+
else {
|
|
175
|
+
var supportedType = ['items', 'summary'];
|
|
176
|
+
//Passed all validations, Construct API url
|
|
177
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'];
|
|
178
|
+
|
|
179
|
+
if(supportedType.indexOf(options.type) > -1) {
|
|
180
|
+
switch(options.type) {
|
|
181
|
+
case 'items':
|
|
182
|
+
url += self.config.ANALYTICS_API_URLS.getAnalyticProductItems;
|
|
183
|
+
break;
|
|
184
|
+
case 'summary':
|
|
185
|
+
url += self.config.ANALYTICS_API_URLS.getAnalyticProductSummary;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
189
|
+
|
|
190
|
+
var params = { userid: options.userid, productcode: options.productcode };
|
|
191
|
+
|
|
192
|
+
if(options.classid) { params.classid = options.classid; }
|
|
193
|
+
if(options.itemcode) { params.itemcode = options.itemcode; }
|
|
194
|
+
if(options.metrics) { params.metrics = options.metrics; }
|
|
195
|
+
if(options.history) { params.history = options.history; }
|
|
196
|
+
if(options.group) { params.group = options.group; }
|
|
197
|
+
if(options.externalData) { params.externalData = options.externalData; }
|
|
198
|
+
if(options.expiredView && options.type === 'items') { params.expiredView = options.expiredView; }
|
|
199
|
+
|
|
200
|
+
//Setup request with URL and Params
|
|
201
|
+
var requestAPI = request.get(url).query(params);
|
|
202
|
+
|
|
203
|
+
//Setup token in Authorization header
|
|
204
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
205
|
+
|
|
206
|
+
// setting up traceid
|
|
207
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
208
|
+
|
|
209
|
+
//Call Product Timespent Api
|
|
210
|
+
requestAPI.end(function(err, response) {
|
|
211
|
+
if(err) {
|
|
212
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
213
|
+
dfd.reject(err);
|
|
214
|
+
}
|
|
215
|
+
else { dfd.resolve(response.body); }
|
|
216
|
+
});
|
|
217
|
+
} else {
|
|
218
|
+
err.message = err.description = options.type + " is not a valid value of option 'type'";
|
|
219
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
220
|
+
dfd.reject(err);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
err.message = err.description = "Required parameter 'type' or 'userid' or " +
|
|
225
|
+
"'productcode' not found in request options";
|
|
226
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
227
|
+
dfd.reject(err);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return dfd.promise;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
//options = {
|
|
234
|
+
// userprogressid: 'string' // userprogressid
|
|
235
|
+
//}
|
|
236
|
+
function getUserProductAnalyticById(options) {
|
|
237
|
+
var self = this;
|
|
238
|
+
|
|
239
|
+
//Initializing promise
|
|
240
|
+
var dfd = q.defer();
|
|
241
|
+
//Validations
|
|
242
|
+
var err = {};
|
|
243
|
+
if(options && options.userprogressid) {
|
|
244
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
245
|
+
if(err) { dfd.reject(err); }
|
|
246
|
+
else {
|
|
247
|
+
//Passed all validations, Construct API url
|
|
248
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
249
|
+
self.config.ANALYTICS_API_URLS.getAnalyticProductById;
|
|
250
|
+
url = helpers.api.constructAPIUrl(url, {
|
|
251
|
+
orgId: self.orgId, userProgressId: options.userprogressid
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
//Setup request with URL and Params
|
|
255
|
+
var requestAPI = request.get(url);
|
|
256
|
+
|
|
257
|
+
//Setup token in Authorization header
|
|
258
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
259
|
+
|
|
260
|
+
// setting up traceid
|
|
261
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
262
|
+
|
|
263
|
+
//Call Product Timespent Api
|
|
264
|
+
requestAPI.end(function(err, response) {
|
|
265
|
+
if(err) {
|
|
266
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
267
|
+
dfd.reject(err);
|
|
268
|
+
}
|
|
269
|
+
else { dfd.resolve(response.body); }
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
err.message = err.description = "Required parameter 'userprogressid' not " +
|
|
274
|
+
"found in request options";
|
|
275
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
276
|
+
dfd.reject(err);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return dfd.promise;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
//options = {
|
|
283
|
+
// ext_user_id: <ext_user_id>, // mandatory
|
|
284
|
+
// productcode: <productcode>, // mandatory
|
|
285
|
+
// itemcode: <itemcode>, // mandatory
|
|
286
|
+
// submission_order: number, // mandatory
|
|
287
|
+
// part: number, // mandatory
|
|
288
|
+
// classid: <classid>, // optional
|
|
289
|
+
//}
|
|
290
|
+
function getExternalDataForUserAnalyticItem(options) {
|
|
291
|
+
var self = this;
|
|
292
|
+
var dfd = q.defer();
|
|
293
|
+
// Validations
|
|
294
|
+
var err = {};
|
|
295
|
+
if(options && options.ext_user_id && options.productcode && options.itemcode &&
|
|
296
|
+
options.submission_order && options.part) {
|
|
297
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
298
|
+
if(err) { dfd.reject(err); }
|
|
299
|
+
else {
|
|
300
|
+
// Passed all validations, Construct API url
|
|
301
|
+
var url = self.config.DEFAULT_HOSTS.ANALYTICS +
|
|
302
|
+
self.config.ANALYTICS_API_URLS.getExternalDataForUserAnalyticItem;
|
|
303
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
304
|
+
|
|
305
|
+
var params = {
|
|
306
|
+
ext_user_id: options.ext_user_id,
|
|
307
|
+
productcode: options.productcode,
|
|
308
|
+
itemcode: options.itemcode,
|
|
309
|
+
submission_order: options.submission_order,
|
|
310
|
+
part: options.part
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
if(options.classid) { params.classid = options.classid; }
|
|
314
|
+
|
|
315
|
+
// Setup request with URL and Params
|
|
316
|
+
var requestAPI = request.get(url).query(params);
|
|
317
|
+
|
|
318
|
+
// Setup token in Authorization header
|
|
319
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
320
|
+
|
|
321
|
+
// setting up traceid
|
|
322
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
323
|
+
|
|
324
|
+
// Call Product Timespent Api
|
|
325
|
+
requestAPI.end(function(err, response) {
|
|
326
|
+
if(err) {
|
|
327
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
328
|
+
dfd.reject(err);
|
|
329
|
+
}
|
|
330
|
+
else { dfd.resolve(response.body); }
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
err.message = err.description = "Required parameters 'ext_user_id' or 'productcode' or 'itemcode'" +
|
|
335
|
+
" or 'submission_order' or 'part'are not found in request options";
|
|
336
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
337
|
+
dfd.reject(err);
|
|
338
|
+
}
|
|
339
|
+
return dfd.promise;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
//options = {
|
|
343
|
+
// userid: <userid>
|
|
344
|
+
// productid: <productid>,
|
|
345
|
+
// classid: <classid>, // OPTIONAL
|
|
346
|
+
//}
|
|
347
|
+
function archiveUserAnalytics(options) {
|
|
348
|
+
var self = this, err = {};
|
|
349
|
+
//Initializing promise
|
|
350
|
+
var dfd = q.defer();
|
|
351
|
+
if(options && options.userid && options.productid) {
|
|
352
|
+
//Validations
|
|
353
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
354
|
+
if(err) { dfd.reject(err); }
|
|
355
|
+
else {
|
|
356
|
+
var params = {};
|
|
357
|
+
//Passed all validations, Construct API url
|
|
358
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
359
|
+
self.config.ANALYTICS_API_URLS.archiveUserAnalytics;
|
|
360
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
361
|
+
|
|
362
|
+
if(options.userid) { params.userid = options.userid; }
|
|
363
|
+
if(options.productid) { params.productid = options.productid; }
|
|
364
|
+
if(options.classid) { params.classid = options.classid; }
|
|
365
|
+
|
|
366
|
+
//Setup request with URL and Params
|
|
367
|
+
var requestAPI = request.post(url).query(params)
|
|
368
|
+
.set('Content-Type', 'application/json');
|
|
369
|
+
|
|
370
|
+
//Setup token in Authorization header
|
|
371
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
372
|
+
|
|
373
|
+
// setting up traceid
|
|
374
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
375
|
+
|
|
376
|
+
requestAPI.end(function(err, response) {
|
|
377
|
+
if(err) {
|
|
378
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
379
|
+
dfd.reject(err);
|
|
380
|
+
}
|
|
381
|
+
else { dfd.resolve(response.body); }
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
} else {
|
|
385
|
+
err.message = err.description = 'Mandatory parameter [userid, productid] ' +
|
|
386
|
+
'not found in request options';
|
|
387
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
388
|
+
dfd.reject(err);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return dfd.promise;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
//options = {
|
|
395
|
+
// userid: <userid>, // OPTIONAL
|
|
396
|
+
// productid: <productid>, // OPTIONAL
|
|
397
|
+
// classid: <classid>, // OPTIONAL
|
|
398
|
+
// lookup: 'string', // Search query (',' separated key value pairs), e.g. key1:val1,key2:val2,key3:val3
|
|
399
|
+
// cursor: '', // cursor to next set of documents
|
|
400
|
+
// limit: '' // limit of documents per function call
|
|
401
|
+
//}
|
|
402
|
+
function searchUserProductAnalytics(options) {
|
|
403
|
+
var self = this, err = {};
|
|
404
|
+
//Initializing promise
|
|
405
|
+
var dfd = q.defer();
|
|
406
|
+
|
|
407
|
+
//Validations
|
|
408
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
409
|
+
if(err) { dfd.reject(err); }
|
|
410
|
+
else {
|
|
411
|
+
var params = {};
|
|
412
|
+
//Passed all validations, Construct API url
|
|
413
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
414
|
+
self.config.ANALYTICS_API_URLS.searchUserProductAnalytics;
|
|
415
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
416
|
+
|
|
417
|
+
if(options.userid) { params.userid = options.userid; }
|
|
418
|
+
if(options.productid) { params.productid = options.productid; }
|
|
419
|
+
if(options.classid) { params.classid = options.classid; }
|
|
420
|
+
if(options.lookup) { params.lookup = options.lookup; }
|
|
421
|
+
if(options.cursor) { params.cursor = options.cursor; }
|
|
422
|
+
if(options.limit) { params.limit = options.limit; }
|
|
423
|
+
|
|
424
|
+
//Setup request with URL and Params
|
|
425
|
+
var requestAPI = request.get(url).query(params);
|
|
426
|
+
|
|
427
|
+
//Setup token in Authorization header
|
|
428
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
429
|
+
|
|
430
|
+
// setting up traceid
|
|
431
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
432
|
+
|
|
433
|
+
requestAPI.end(function(err, response) {
|
|
434
|
+
if(err) {
|
|
435
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
436
|
+
dfd.reject(err);
|
|
437
|
+
}
|
|
438
|
+
else { dfd.resolve(response.body); }
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
return dfd.promise;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* This function returns the count and submissions of a user in a class for a product.
|
|
447
|
+
* options = {
|
|
448
|
+
* userid: string,
|
|
449
|
+
* classid: string,
|
|
450
|
+
* productcode: string,
|
|
451
|
+
* gradingStatus: string, // optional, type of submissions required.
|
|
452
|
+
* Possible values: ['not-started', 'submitted', 'evaluated']
|
|
453
|
+
* }
|
|
454
|
+
*/
|
|
455
|
+
function getUserClassRecentSubmissions(options) {
|
|
456
|
+
var self = this;
|
|
457
|
+
var dfd = q.defer(), err = {};
|
|
458
|
+
|
|
459
|
+
if(options && options.classid && options.productcode && options.userid) {
|
|
460
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
461
|
+
if(err) { dfd.reject(err); }
|
|
462
|
+
else {
|
|
463
|
+
// Passed all validations, Constructing URL
|
|
464
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
465
|
+
self.config.ANALYTICS_API_URLS.getUserClassRecentSubmissions;
|
|
466
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
467
|
+
|
|
468
|
+
// Setup Query Params
|
|
469
|
+
var queryParams = {
|
|
470
|
+
userid: options.userid,
|
|
471
|
+
classid: options.classid,
|
|
472
|
+
productcode: options.productcode
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
if(options.gradingStatus) { queryParams.gradingStatus = options.gradingStatus; }
|
|
476
|
+
|
|
477
|
+
// Setup Request with url and params
|
|
478
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
479
|
+
// Setup token in Authorization Header
|
|
480
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
481
|
+
|
|
482
|
+
// setting up traceid
|
|
483
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
484
|
+
|
|
485
|
+
// Call GET Class Product Recent Pending Submissions
|
|
486
|
+
requestAPI.end(function(error, response) {
|
|
487
|
+
if(error) {
|
|
488
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
489
|
+
dfd.reject(err);
|
|
490
|
+
} else {
|
|
491
|
+
dfd.resolve(response.body);
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
err.message = err.description = 'Mandatory parameters ["classid", "productcode", "userid"]' +
|
|
498
|
+
' not found in request options.';
|
|
499
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
500
|
+
dfd.reject(err);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
return dfd.promise;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
//options = {
|
|
507
|
+
// classid: 'string',
|
|
508
|
+
// productcode: 'string',
|
|
509
|
+
//}
|
|
510
|
+
function getStudentsWithEvaluatedOnce(options) {
|
|
511
|
+
var self = this, err = {};
|
|
512
|
+
//Initializing promise
|
|
513
|
+
var dfd = q.defer();
|
|
514
|
+
if(options && options.classid && options.productcode) {
|
|
515
|
+
//Validations
|
|
516
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
517
|
+
if(err) { dfd.reject(err); }
|
|
518
|
+
else {
|
|
519
|
+
// Passed all validations, Construct API url
|
|
520
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
521
|
+
self.config.ANALYTICS_API_URLS.getStudentsWithEvaluatedOnce;
|
|
522
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
523
|
+
|
|
524
|
+
// Setup params
|
|
525
|
+
var params = {
|
|
526
|
+
classid: options.classid,
|
|
527
|
+
productcode: options.productcode
|
|
528
|
+
};
|
|
529
|
+
// Setup request with URL and Params
|
|
530
|
+
var requestAPI = request.get(url).query(params);
|
|
531
|
+
// Setup token in Authorization header
|
|
532
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
533
|
+
|
|
534
|
+
// setting up traceid
|
|
535
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
536
|
+
|
|
537
|
+
requestAPI.end(function(error, response) {
|
|
538
|
+
if(error) {
|
|
539
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
540
|
+
dfd.reject(err);
|
|
541
|
+
}
|
|
542
|
+
else { dfd.resolve(response.body); }
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
} else {
|
|
546
|
+
err.message = err.description = 'Required parameter classid or ' +
|
|
547
|
+
'productcode not found in request options.';
|
|
548
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
549
|
+
dfd.reject(err);
|
|
550
|
+
}
|
|
551
|
+
return dfd.promise;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
/*options = {
|
|
556
|
+
userid: <userid>, productcode: <productcode>,
|
|
557
|
+
classid: <classid>, // OPTIONAL
|
|
558
|
+
itemcode: <itemcode> // OPTIONAL
|
|
559
|
+
key: <string> // OPTIONAL
|
|
560
|
+
}*/
|
|
561
|
+
function getAppState(options) {
|
|
562
|
+
var self = this;
|
|
563
|
+
var dfd = q.defer();
|
|
564
|
+
// Validations
|
|
565
|
+
var err = {};
|
|
566
|
+
if(options && options.userid && options.productcode) {
|
|
567
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
568
|
+
if(err) { dfd.reject(err); }
|
|
569
|
+
else {
|
|
570
|
+
// Passed all validations, Construct API url
|
|
571
|
+
var url = self.config.DEFAULT_HOSTS.ANALYTICS +
|
|
572
|
+
self.config.ANALYTICS_API_URLS.appState;
|
|
573
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
574
|
+
|
|
575
|
+
var params = { userid: options.userid, productcode: options.productcode };
|
|
576
|
+
if(options.classid) { params.classid = options.classid; }
|
|
577
|
+
if(options.itemcode) { params.itemcode = options.itemcode; }
|
|
578
|
+
if(options.key) { params.key = options.key; }
|
|
579
|
+
|
|
580
|
+
// Setup request with URL and Params
|
|
581
|
+
var requestAPI = request.get(url).query(params);
|
|
582
|
+
|
|
583
|
+
// Setup token in Authorization header
|
|
584
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
585
|
+
|
|
586
|
+
// setting up traceid
|
|
587
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
588
|
+
|
|
589
|
+
// Call Product Timespent Api
|
|
590
|
+
requestAPI.end(function(err, response) {
|
|
591
|
+
if(err) {
|
|
592
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
593
|
+
dfd.reject(err);
|
|
594
|
+
}
|
|
595
|
+
else { dfd.resolve(response.body); }
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
} else {
|
|
599
|
+
err.message = err.description = "Required parameters 'userid' or " +
|
|
600
|
+
"'productcode' are not found in request options";
|
|
601
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
602
|
+
dfd.reject(err);
|
|
603
|
+
}
|
|
604
|
+
return dfd.promise;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/*options = {
|
|
608
|
+
userid: <userid>,
|
|
609
|
+
productcode: <productcode>,
|
|
610
|
+
classid: <classid>, // OPTIONAL
|
|
611
|
+
itemcode: <itemcode> // OPTIONAL
|
|
612
|
+
appdata: <object>,
|
|
613
|
+
}*/
|
|
614
|
+
function updateAppState(options) {
|
|
615
|
+
var self = this;
|
|
616
|
+
var dfd = q.defer();
|
|
617
|
+
// Validations
|
|
618
|
+
var err = {};
|
|
619
|
+
if(options && options.userid && options.productcode && options.appdata) {
|
|
620
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
621
|
+
if(err) { dfd.reject(err); }
|
|
622
|
+
else {
|
|
623
|
+
// Passed all validations, Construct API url
|
|
624
|
+
var url = self.config.DEFAULT_HOSTS.ANALYTICS +
|
|
625
|
+
self.config.ANALYTICS_API_URLS.appState;
|
|
626
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
627
|
+
|
|
628
|
+
var params = { userid: options.userid, productcode: options.productcode };
|
|
629
|
+
if(options.classid) { params.classid = options.classid; }
|
|
630
|
+
if(options.itemcode) { params.itemcode = options.itemcode; }
|
|
631
|
+
|
|
632
|
+
// Setup request with URL and Params
|
|
633
|
+
var requestAPI = request.put(url).query(params)
|
|
634
|
+
.set('Content-Type', 'application/json')
|
|
635
|
+
.set('Accept', 'application/json')
|
|
636
|
+
.send(options.appdata);
|
|
637
|
+
|
|
638
|
+
// Setup token in Authorization header
|
|
639
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
640
|
+
|
|
641
|
+
// setting up traceid
|
|
642
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
643
|
+
|
|
644
|
+
// Call Product Timespent Api
|
|
645
|
+
requestAPI.end(function(err, response) {
|
|
646
|
+
if(err) {
|
|
647
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
648
|
+
dfd.reject(err);
|
|
649
|
+
}
|
|
650
|
+
else { dfd.resolve(response.body); }
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
} else {
|
|
654
|
+
err.message = err.description = "Required parameters 'userid' or 'appdata'" +
|
|
655
|
+
" or 'productcode' are not found in request options";
|
|
656
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
657
|
+
dfd.reject(err);
|
|
658
|
+
}
|
|
659
|
+
return dfd.promise;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/*options = {
|
|
663
|
+
userid: <userid>, productcode: <productcode>,
|
|
664
|
+
classid: <classid>, // OPTIONAL
|
|
665
|
+
itemcode: <itemcode> // OPTIONAL
|
|
666
|
+
key: <string> // OPTIONAL
|
|
667
|
+
}*/
|
|
668
|
+
function deleteAppState(options) {
|
|
669
|
+
var self = this;
|
|
670
|
+
var dfd = q.defer();
|
|
671
|
+
// Validations
|
|
672
|
+
var err = {};
|
|
673
|
+
if(options && options.userid && options.productcode) {
|
|
674
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
675
|
+
if(err) { dfd.reject(err); }
|
|
676
|
+
else {
|
|
677
|
+
// Passed all validations, Construct API url
|
|
678
|
+
var url = self.config.DEFAULT_HOSTS.ANALYTICS +
|
|
679
|
+
self.config.ANALYTICS_API_URLS.appState;
|
|
680
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
681
|
+
|
|
682
|
+
var params = { userid: options.userid, productcode: options.productcode };
|
|
683
|
+
if(options.classid) { params.classid = options.classid; }
|
|
684
|
+
if(options.itemcode) { params.itemcode = options.itemcode; }
|
|
685
|
+
if(options.key) { params.key = options.key; }
|
|
686
|
+
|
|
687
|
+
// Setup request with URL and Params
|
|
688
|
+
var requestAPI = request.delete(url).query(params);
|
|
689
|
+
|
|
690
|
+
// Setup token in Authorization header
|
|
691
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
692
|
+
|
|
693
|
+
// setting up traceid
|
|
694
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
695
|
+
|
|
696
|
+
// Call Product Timespent Api
|
|
697
|
+
requestAPI.end(function(err, response) {
|
|
698
|
+
if(err) {
|
|
699
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
700
|
+
dfd.reject(err);
|
|
701
|
+
}
|
|
702
|
+
else { dfd.resolve(response.body); }
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
} else {
|
|
706
|
+
err.message = err.description = "Required parameters 'userid' or " +
|
|
707
|
+
"'productcode' are not found in request options";
|
|
708
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
709
|
+
dfd.reject(err);
|
|
710
|
+
}
|
|
711
|
+
return dfd.promise;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* This function returns the recent pending submissions in a Class for a Product.
|
|
717
|
+
* options = {
|
|
718
|
+
* classid: string,
|
|
719
|
+
* productcode: string,
|
|
720
|
+
* details: boolean, // optional, if details of submissions is also required.
|
|
721
|
+
* limit: number // optional, number of submissions to be fetched at once (default & max is 100)
|
|
722
|
+
* }
|
|
723
|
+
*/
|
|
724
|
+
function getClassProductRecentPendingSubmissions(options) {
|
|
725
|
+
var self = this;
|
|
726
|
+
var dfd = q.defer(), err = {};
|
|
727
|
+
|
|
728
|
+
if(options && options.classid && options.productcode) {
|
|
729
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
730
|
+
if(err) { dfd.reject(err); }
|
|
731
|
+
else {
|
|
732
|
+
// Passed all validations, Constructing URL
|
|
733
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
734
|
+
self.config.ANALYTICS_API_URLS.getClassProductRecentPendingSubmissions;
|
|
735
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
736
|
+
|
|
737
|
+
// Setup Query Params
|
|
738
|
+
var queryParams = {
|
|
739
|
+
classid: options.classid,
|
|
740
|
+
productcode: options.productcode
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
if(options.details) { queryParams.details = options.details; }
|
|
744
|
+
if(options.limit) { queryParams.limit = options.limit; }
|
|
745
|
+
|
|
746
|
+
// Setup Request with url and params
|
|
747
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
748
|
+
// Setup token in Authorization Header
|
|
749
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
750
|
+
// Call GET Class Product Recent Pending Submissions
|
|
751
|
+
|
|
752
|
+
// setting up traceid
|
|
753
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
754
|
+
|
|
755
|
+
requestAPI.end(function(error, response) {
|
|
756
|
+
if(error) {
|
|
757
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
758
|
+
dfd.reject(err);
|
|
759
|
+
} else {
|
|
760
|
+
dfd.resolve(response.body);
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
else {
|
|
766
|
+
err.message = err.description = 'Mandatory parameters ["classid", "productcode"] not found in ' +
|
|
767
|
+
'request options.';
|
|
768
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
769
|
+
dfd.reject(err);
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
return dfd.promise;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/*options = {
|
|
776
|
+
* classid: 'string', // class uuid
|
|
777
|
+
* productcode: 'string', // product code
|
|
778
|
+
* includeContext: 'boolean' // includse context or heirarchy (optional)
|
|
779
|
+
*}
|
|
780
|
+
*/
|
|
781
|
+
function getClassRecord(options) {
|
|
782
|
+
var self = this;
|
|
783
|
+
|
|
784
|
+
//Initializing DFD
|
|
785
|
+
var dfd = q.defer(), err = {};
|
|
786
|
+
|
|
787
|
+
// Validations
|
|
788
|
+
if(options && options.classid && options.productcode) {
|
|
789
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
790
|
+
if(err){ dfd.reject(err); }
|
|
791
|
+
else {
|
|
792
|
+
// Passed all validations, Constructing URL
|
|
793
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] + self.config.ANALYTICS_API_URLS.getClassRecord;
|
|
794
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
795
|
+
|
|
796
|
+
// Setup Query Params
|
|
797
|
+
var queryParams = {
|
|
798
|
+
classid: options.classid,
|
|
799
|
+
productcode: options.productcode,
|
|
800
|
+
includeContext: options.includeContext
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// Setup Request with url and params
|
|
804
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
805
|
+
// Setup token in Authorization Header
|
|
806
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
807
|
+
|
|
808
|
+
// setting up traceid
|
|
809
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
810
|
+
|
|
811
|
+
// Call GET GET CLASS RECORD ITEM
|
|
812
|
+
requestAPI.end(function(error, response) {
|
|
813
|
+
if(error) {
|
|
814
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
815
|
+
dfd.reject(err);
|
|
816
|
+
} else {
|
|
817
|
+
dfd.resolve(response.body)
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
} else {
|
|
822
|
+
err.message = err.description = 'Required parameter classid or ' +
|
|
823
|
+
'productcode not found in request options.';
|
|
824
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
825
|
+
dfd.reject(err);
|
|
826
|
+
}
|
|
827
|
+
return dfd.promise;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/*options = {
|
|
831
|
+
* classid: 'string', // class uuid
|
|
832
|
+
* productcode: 'string', // product code
|
|
833
|
+
* item-code: 'string' // item-code of item(optional)
|
|
834
|
+
*}
|
|
835
|
+
*/
|
|
836
|
+
function getClassRecordItemAggregations(options) {
|
|
837
|
+
var self = this;
|
|
838
|
+
|
|
839
|
+
//Initializing DFD
|
|
840
|
+
var dfd = q.defer(), err = {};
|
|
841
|
+
|
|
842
|
+
// Validations
|
|
843
|
+
if(options && options.classid && options.productcode) {
|
|
844
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
845
|
+
if(err){ dfd.reject(err); }
|
|
846
|
+
else {
|
|
847
|
+
// Passed all validations, Constructing URL
|
|
848
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] + self.config.ANALYTICS_API_URLS.getClassRecordItemAggregations;
|
|
849
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
850
|
+
|
|
851
|
+
// Setup Query Params
|
|
852
|
+
var queryParams = {
|
|
853
|
+
classid: options.classid,
|
|
854
|
+
productcode: options.productcode,
|
|
855
|
+
'item-code': options['item-code']
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// Setup Request with url and params
|
|
859
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
860
|
+
// Setup token in Authorization Header
|
|
861
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
862
|
+
|
|
863
|
+
// setting up traceid
|
|
864
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
865
|
+
|
|
866
|
+
// Call GET GET CLASS RECORD ITEM
|
|
867
|
+
requestAPI.end(function(error, response) {
|
|
868
|
+
if(error) {
|
|
869
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
870
|
+
dfd.reject(err);
|
|
871
|
+
} else {
|
|
872
|
+
dfd.resolve(response.body)
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
} else {
|
|
877
|
+
err.message = err.description = 'Required parameter classid or ' +
|
|
878
|
+
'productcode not found in request options.';
|
|
879
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
880
|
+
dfd.reject(err);
|
|
881
|
+
}
|
|
882
|
+
return dfd.promise;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/*options = {
|
|
886
|
+
* classid: 'string', // class uuid(mandatory)
|
|
887
|
+
* productcode: 'string', // product code(optional)
|
|
888
|
+
* 'item-code': 'string', // itemcode of item(optional)
|
|
889
|
+
* groupid: 'string', // groupid of a group(optional)
|
|
890
|
+
* id: 'string' // id of showcase record item(optional)
|
|
891
|
+
*}
|
|
892
|
+
*/
|
|
893
|
+
function getShowcaseRecordOfAClass(options) {
|
|
894
|
+
var self = this;
|
|
895
|
+
|
|
896
|
+
//Initializing DFD
|
|
897
|
+
var dfd = q.defer(), err = {};
|
|
898
|
+
|
|
899
|
+
// Validations
|
|
900
|
+
if(options && options.classid) {
|
|
901
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
902
|
+
if(err){ dfd.reject(err); }
|
|
903
|
+
else {
|
|
904
|
+
// Passed all validations, Constructing URL
|
|
905
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] + self.config.ANALYTICS_API_URLS.getShowcaseRecordOfAClass;
|
|
906
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
907
|
+
|
|
908
|
+
// Setup Query Params
|
|
909
|
+
var queryParams = {
|
|
910
|
+
classid: options.classid
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
if(options.productcode) { queryParams.productcode = options.productcode; }
|
|
914
|
+
if(options.groupid) { queryParams.groupid = options.groupid; }
|
|
915
|
+
if(options['item-code']) { queryParams['item-code'] = options['item-code']; }
|
|
916
|
+
if(options.id) { queryParams.id = options.id; }
|
|
917
|
+
|
|
918
|
+
// Setup Request with url and params
|
|
919
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
920
|
+
// Setup token in Authorization Header
|
|
921
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
922
|
+
|
|
923
|
+
// setting up traceid
|
|
924
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
925
|
+
|
|
926
|
+
// Call GET GET CLASS RECORD ITEM
|
|
927
|
+
requestAPI.end(function(error, response) {
|
|
928
|
+
if(error) {
|
|
929
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
930
|
+
dfd.reject(err);
|
|
931
|
+
} else {
|
|
932
|
+
dfd.resolve(response.body);
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
} else {
|
|
937
|
+
err.message = err.description = 'Required parameter classid not found in request options.';
|
|
938
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
939
|
+
dfd.reject(err);
|
|
940
|
+
}
|
|
941
|
+
return dfd.promise;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* options = {
|
|
946
|
+
* classid: 'string', // mandatory, class uuid
|
|
947
|
+
* productcode: 'string', // mandatory, product code
|
|
948
|
+
* groupid: 'string', // mandatory, group id
|
|
949
|
+
* itemcode: 'string', // optional, item code of the group LO whose GR is required
|
|
950
|
+
* history: boolean // optional, if true give all the submissions else give only the latest submission
|
|
951
|
+
* }
|
|
952
|
+
*/
|
|
953
|
+
function getGroupRecord(options) {
|
|
954
|
+
var self = this;
|
|
955
|
+
|
|
956
|
+
//Initializing DFD
|
|
957
|
+
var dfd = q.defer(), err = {};
|
|
958
|
+
|
|
959
|
+
// Validations
|
|
960
|
+
if(options && options.classid && options.productcode && options.groupid) {
|
|
961
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
962
|
+
if(err){ dfd.reject(err); }
|
|
963
|
+
else {
|
|
964
|
+
// Passed all validations, Constructing URL
|
|
965
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] + self.config.ANALYTICS_API_URLS.getGroupRecord;
|
|
966
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
967
|
+
|
|
968
|
+
// Setup Query Params
|
|
969
|
+
var queryParams = {
|
|
970
|
+
classid: options.classid,
|
|
971
|
+
productcode: options.productcode,
|
|
972
|
+
groupid: options.groupid
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
if(options.itemcode) { queryParams.itemcode = options.itemcode; }
|
|
976
|
+
if(options.history) { queryParams.history = options.history; }
|
|
977
|
+
|
|
978
|
+
// Setup Request with url and params
|
|
979
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
980
|
+
// Setup token in Authorization Header
|
|
981
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
982
|
+
|
|
983
|
+
// setting up traceid
|
|
984
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
985
|
+
|
|
986
|
+
// Call GET GET GROUP RECORD ITEM
|
|
987
|
+
requestAPI.end(function(error, response) {
|
|
988
|
+
if(error) {
|
|
989
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
990
|
+
dfd.reject(err);
|
|
991
|
+
} else {
|
|
992
|
+
dfd.resolve(response.body)
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
} else {
|
|
997
|
+
err.message = err.description = 'Required parameter classid or ' +
|
|
998
|
+
'productcode or groupid not found in request options.';
|
|
999
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1000
|
+
dfd.reject(err);
|
|
1001
|
+
}
|
|
1002
|
+
return dfd.promise;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* This function returns the recent pending submissions of all the groups in a Class for a Product.
|
|
1007
|
+
* options = {
|
|
1008
|
+
* classid: string,
|
|
1009
|
+
* productcode: string,
|
|
1010
|
+
* details: boolean, // optional, if details of submissions is also required.
|
|
1011
|
+
* limit: number // optional, number of submissions to be fetched at once (default & max is 100)
|
|
1012
|
+
* }
|
|
1013
|
+
*/
|
|
1014
|
+
function getClassGroupsRecentPendingSubmissions(options) {
|
|
1015
|
+
var self = this;
|
|
1016
|
+
var dfd = q.defer(), err = {};
|
|
1017
|
+
|
|
1018
|
+
if(options && options.classid && options.productcode) {
|
|
1019
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1020
|
+
if(err) { dfd.reject(err); }
|
|
1021
|
+
else {
|
|
1022
|
+
// Passed all validations, Constructing URL
|
|
1023
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
1024
|
+
self.config.ANALYTICS_API_URLS.getClassGroupsRecentPendingSubmissions;
|
|
1025
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1026
|
+
|
|
1027
|
+
// Setup Query Params
|
|
1028
|
+
var queryParams = {
|
|
1029
|
+
classid: options.classid,
|
|
1030
|
+
productcode: options.productcode
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
if(options.details) { queryParams.details = options.details; }
|
|
1034
|
+
if(options.limit) { queryParams.limit = options.limit; }
|
|
1035
|
+
|
|
1036
|
+
// Setup Request with url and params
|
|
1037
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
1038
|
+
// Setup token in Authorization Header
|
|
1039
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1040
|
+
|
|
1041
|
+
// setting up traceid
|
|
1042
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1043
|
+
|
|
1044
|
+
// Call GET Class Product Recent Pending Submissions of all groups
|
|
1045
|
+
requestAPI.end(function(error, response) {
|
|
1046
|
+
if(error) {
|
|
1047
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1048
|
+
dfd.reject(err);
|
|
1049
|
+
} else {
|
|
1050
|
+
dfd.resolve(response.body);
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
else {
|
|
1056
|
+
err.message = err.description = 'Mandatory parameters ["classid", "productcode"] not found in ' +
|
|
1057
|
+
'request options.';
|
|
1058
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1059
|
+
dfd.reject(err);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
return dfd.promise;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* options = {
|
|
1067
|
+
* classid: 'string', //mandatory
|
|
1068
|
+
* productcode: 'string' //mandatory
|
|
1069
|
+
*}
|
|
1070
|
+
*/
|
|
1071
|
+
function getGroupsWithEvaluatedOnce(options) {
|
|
1072
|
+
var self = this, err = {};
|
|
1073
|
+
//Initializing promise
|
|
1074
|
+
var dfd = q.defer();
|
|
1075
|
+
if(options && options.classid && options.productcode) {
|
|
1076
|
+
//Validations
|
|
1077
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1078
|
+
if(err) { dfd.reject(err); }
|
|
1079
|
+
else {
|
|
1080
|
+
// Passed all validations, Construct API url
|
|
1081
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
1082
|
+
self.config.ANALYTICS_API_URLS.getGroupsWithEvaluatedOnce;
|
|
1083
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1084
|
+
|
|
1085
|
+
// Setup params
|
|
1086
|
+
var params = {
|
|
1087
|
+
classid: options.classid,
|
|
1088
|
+
productcode: options.productcode
|
|
1089
|
+
};
|
|
1090
|
+
// Setup request with URL and Params
|
|
1091
|
+
var requestAPI = request.get(url).query(params);
|
|
1092
|
+
// Setup token in Authorization header
|
|
1093
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1094
|
+
|
|
1095
|
+
// setting up traceid
|
|
1096
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1097
|
+
|
|
1098
|
+
requestAPI.end(function(error, response) {
|
|
1099
|
+
if(error) {
|
|
1100
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1101
|
+
dfd.reject(err);
|
|
1102
|
+
}
|
|
1103
|
+
else { dfd.resolve(response.body); }
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
} else {
|
|
1107
|
+
err.message = err.description = 'Required parameter classid or ' +
|
|
1108
|
+
'productcode not found in request options.';
|
|
1109
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1110
|
+
dfd.reject(err);
|
|
1111
|
+
}
|
|
1112
|
+
return dfd.promise;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
//options = {
|
|
1116
|
+
// classid: 'string',
|
|
1117
|
+
// productcode: 'string',
|
|
1118
|
+
// userid: 'string' //optional
|
|
1119
|
+
//}
|
|
1120
|
+
|
|
1121
|
+
function getClassRecordUserAggregations(options) {
|
|
1122
|
+
var self = this, err = {};
|
|
1123
|
+
//Initializing promise
|
|
1124
|
+
var dfd = q.defer();
|
|
1125
|
+
if(options && options.classid && options.productcode) {
|
|
1126
|
+
//Validations
|
|
1127
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1128
|
+
if(err) { dfd.reject(err); }
|
|
1129
|
+
else {
|
|
1130
|
+
// Passed all validations, Construct API url
|
|
1131
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
1132
|
+
self.config.ANALYTICS_API_URLS.getClassRecordUserAggregations;
|
|
1133
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1134
|
+
|
|
1135
|
+
// Setup params
|
|
1136
|
+
var params = {
|
|
1137
|
+
classid: options.classid,
|
|
1138
|
+
productcode: options.productcode,
|
|
1139
|
+
userid: options.userid
|
|
1140
|
+
};
|
|
1141
|
+
// Setup request with URL and Params
|
|
1142
|
+
var requestAPI = request.get(url).query(params);
|
|
1143
|
+
// Setup token in Authorization header
|
|
1144
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1145
|
+
|
|
1146
|
+
// setting up traceid
|
|
1147
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1148
|
+
|
|
1149
|
+
requestAPI.end(function(error, response) {
|
|
1150
|
+
if(error) {
|
|
1151
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1152
|
+
dfd.reject(err);
|
|
1153
|
+
}
|
|
1154
|
+
else { dfd.resolve(response.body); }
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
} else {
|
|
1158
|
+
err.message = err.description = 'Required parameter classid or ' +
|
|
1159
|
+
'productcode not found in request options.';
|
|
1160
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1161
|
+
dfd.reject(err);
|
|
1162
|
+
}
|
|
1163
|
+
return dfd.promise;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
//options = {
|
|
1167
|
+
// type: ['stat' / 'timeseries'],
|
|
1168
|
+
// analyticsDataType: ['enrolments' / 'logins']
|
|
1169
|
+
// classid: 'string',
|
|
1170
|
+
// range: '', // for type - stat // OPTIONAL
|
|
1171
|
+
// start: '', // time(ms) - start interval // OPTIONAL
|
|
1172
|
+
// end: '' // time(ms) - end interval // OPTIONAL
|
|
1173
|
+
// interval: '' The interval at which counters are displayed. Possible values are five_minutes, half_hour, hour, six_day, day, week, and month. Default interval is day. // Only for type - timeseries // OPTIONAL
|
|
1174
|
+
//}
|
|
1175
|
+
function getClassAnalytics(options) {
|
|
1176
|
+
var self = this;
|
|
1177
|
+
|
|
1178
|
+
//Initializing promise
|
|
1179
|
+
var dfd = q.defer();
|
|
1180
|
+
//Validations
|
|
1181
|
+
var err = {};
|
|
1182
|
+
if(options && options.type && options.analyticsDataType && options.classid) {
|
|
1183
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1184
|
+
if(err) { dfd.reject(err); }
|
|
1185
|
+
else {
|
|
1186
|
+
err = {};
|
|
1187
|
+
if((!options.range && !options.interval) ||
|
|
1188
|
+
(options.range && options.type === 'stat') ||
|
|
1189
|
+
(options.interval && options.type === 'timeseries'))
|
|
1190
|
+
{
|
|
1191
|
+
var allowedAnalyticsDataType = ['enrolments', 'logins'];
|
|
1192
|
+
if(allowedAnalyticsDataType.indexOf(options.analyticsDataType) > -1) {
|
|
1193
|
+
//Passed all validations, Construct API url
|
|
1194
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
1195
|
+
self.config.ANALYTICS_API_URLS.getClassAnalytics;
|
|
1196
|
+
url = helpers.api.constructAPIUrl(url, {
|
|
1197
|
+
orgId: self.orgId, type: options.type,
|
|
1198
|
+
analyticsDataType: options.analyticsDataType
|
|
1199
|
+
});
|
|
1200
|
+
|
|
1201
|
+
var params = { classid: options.classid };
|
|
1202
|
+
if(options) {
|
|
1203
|
+
if(options.range) { params.range = options.range; }
|
|
1204
|
+
if(options.start) { params.start = options.start; }
|
|
1205
|
+
if(options.end) { params.end = options.end; }
|
|
1206
|
+
if(options.interval) { params.interval = options.interval; }
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
//Setup request with URL and Params
|
|
1210
|
+
var requestAPI = request.get(url).query(params);
|
|
1211
|
+
|
|
1212
|
+
//Setup token in Authorization header
|
|
1213
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1214
|
+
|
|
1215
|
+
// setting up traceid
|
|
1216
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1217
|
+
|
|
1218
|
+
//Call Product Timespent Api
|
|
1219
|
+
requestAPI.end(function(err, response) {
|
|
1220
|
+
if(err) {
|
|
1221
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
1222
|
+
dfd.reject(err);
|
|
1223
|
+
}
|
|
1224
|
+
else { dfd.resolve(response.body); }
|
|
1225
|
+
});
|
|
1226
|
+
} else {
|
|
1227
|
+
err.message = err.description = 'analyticsDataType: ' +
|
|
1228
|
+
options.analyticsDataType + ' is not supported';
|
|
1229
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1230
|
+
dfd.reject(err);
|
|
1231
|
+
}
|
|
1232
|
+
} else {
|
|
1233
|
+
err.message = err.description = 'Range should be defined for type - ' +
|
|
1234
|
+
'"stat" and Interval should be defined for type - "timeseries"';
|
|
1235
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1236
|
+
dfd.reject(err);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
} else {
|
|
1240
|
+
err.message = err.description = 'Required options ["type", "analyticsDataType",' +
|
|
1241
|
+
' "classid"] not found in request options';
|
|
1242
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1243
|
+
dfd.reject(err);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
return dfd.promise;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
//options = {
|
|
1250
|
+
// useranalyticid: <userid>,
|
|
1251
|
+
// cursor: '', // OPTIONAL cursor to next set of documents
|
|
1252
|
+
// limit: '' // OPTIONAL limit of documents per function call (Default is 5)
|
|
1253
|
+
//}
|
|
1254
|
+
function getArchivedUserAnalytics(options) {
|
|
1255
|
+
var self = this;
|
|
1256
|
+
|
|
1257
|
+
//Initializing promise
|
|
1258
|
+
var dfd = q.defer();
|
|
1259
|
+
//Validations
|
|
1260
|
+
var err = {};
|
|
1261
|
+
if(options && options.useranalyticid) {
|
|
1262
|
+
err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1263
|
+
if(err) { dfd.reject(err); }
|
|
1264
|
+
else {
|
|
1265
|
+
//Passed all validations, Construct API url
|
|
1266
|
+
var url = self.config.DEFAULT_HOSTS['ANALYTICS'] +
|
|
1267
|
+
self.config.ANALYTICS_API_URLS.getArchivedUserAnalytics;
|
|
1268
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1269
|
+
var params = { useranalyticid: options.useranalyticid };
|
|
1270
|
+
if(options) {
|
|
1271
|
+
if(options.cursor) { params.cursor = options.cursor; }
|
|
1272
|
+
if(options.limit) { params.limit = options.limit; }
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
//Setup request with URL and Params
|
|
1276
|
+
var requestAPI = request.get(url).query(params);
|
|
1277
|
+
|
|
1278
|
+
//Setup token in Authorization header
|
|
1279
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1280
|
+
|
|
1281
|
+
// setting up traceid
|
|
1282
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1283
|
+
|
|
1284
|
+
//Call Product Timespent Api
|
|
1285
|
+
requestAPI.end(function(err, response) {
|
|
1286
|
+
if(err) {
|
|
1287
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
1288
|
+
dfd.reject(err);
|
|
1289
|
+
}
|
|
1290
|
+
else { dfd.resolve(response.body); }
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
} else {
|
|
1294
|
+
err.message = err.description = "Mandatory field 'useranalyticid' not found" +
|
|
1295
|
+
" in request options";
|
|
1296
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1297
|
+
dfd.reject(err);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
return dfd.promise;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/*********************************************************
|
|
1304
|
+
* This function converts the data from questions format to
|
|
1305
|
+
* Learning Objective Format.
|
|
1306
|
+
*********************************************************/
|
|
1307
|
+
function getQuestionProgressByLearningObjective(questionsArray) {
|
|
1308
|
+
var learningObjectiveFormat = {};
|
|
1309
|
+
for(var i = 0; i < questionsArray.length; i++) {
|
|
1310
|
+
var questionLearningObjectives = questionsArray[i]['learning-objectives'];
|
|
1311
|
+
for(var j = 0; j < questionLearningObjectives.length; j++) {
|
|
1312
|
+
var analytics;
|
|
1313
|
+
var correct;
|
|
1314
|
+
var questionDataMap;
|
|
1315
|
+
if(!learningObjectiveFormat[questionLearningObjectives[j]]) {
|
|
1316
|
+
correct = 0;
|
|
1317
|
+
analytics = questionsArray[i].__analytics;
|
|
1318
|
+
if(analytics.statusEvaluation === 'correct') {
|
|
1319
|
+
correct++;
|
|
1320
|
+
}
|
|
1321
|
+
var questionsMap = {
|
|
1322
|
+
'status': {
|
|
1323
|
+
'correct': correct,
|
|
1324
|
+
'total': 1
|
|
1325
|
+
},
|
|
1326
|
+
'questions': []
|
|
1327
|
+
};
|
|
1328
|
+
questionDataMap = {
|
|
1329
|
+
'question-code': questionsArray[i].questionCode,
|
|
1330
|
+
'analytics': analytics
|
|
1331
|
+
};
|
|
1332
|
+
questionsMap.questions.push(questionDataMap);
|
|
1333
|
+
learningObjectiveFormat[questionLearningObjectives[j]] = questionsMap;
|
|
1334
|
+
}
|
|
1335
|
+
else {
|
|
1336
|
+
var savedQuestionsMap = learningObjectiveFormat[questionLearningObjectives[j]];
|
|
1337
|
+
analytics = questionsArray[i].__analytics;
|
|
1338
|
+
if(analytics.statusEvaluation === 'correct') {
|
|
1339
|
+
correct = savedQuestionsMap.status.correct;
|
|
1340
|
+
savedQuestionsMap.status.correct = correct + 1;
|
|
1341
|
+
}
|
|
1342
|
+
var total = savedQuestionsMap.status.total;
|
|
1343
|
+
savedQuestionsMap.status.total = total + 1;
|
|
1344
|
+
questionDataMap = {
|
|
1345
|
+
'question-code': questionsArray[i].questionCode,
|
|
1346
|
+
'analytics': analytics
|
|
1347
|
+
};
|
|
1348
|
+
savedQuestionsMap.questions.push(questionDataMap);
|
|
1349
|
+
learningObjectiveFormat[questionLearningObjectives[j]] = savedQuestionsMap;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
return learningObjectiveFormat;
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
/* options = {
|
|
1357
|
+
"classid": "string", // required
|
|
1358
|
+
};
|
|
1359
|
+
*/
|
|
1360
|
+
function getAllAssignedPathsOfClass(options) {
|
|
1361
|
+
var self = this;
|
|
1362
|
+
// Initializing promise
|
|
1363
|
+
var dfd = q.defer();
|
|
1364
|
+
var err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1365
|
+
if(err) { dfd.reject(err); }
|
|
1366
|
+
else {
|
|
1367
|
+
if(options && options.classid) {
|
|
1368
|
+
|
|
1369
|
+
// Passed all validations, Contruct API url
|
|
1370
|
+
var url = self.config.DEFAULT_HOSTS.ANALYTICS + self.config.ANALYTICS_API_URLS.getAllAssignedPathsOfClass;
|
|
1371
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1372
|
+
|
|
1373
|
+
var queryParams = { classid: options.classid };
|
|
1374
|
+
|
|
1375
|
+
// Setup request with URL and Params
|
|
1376
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
1377
|
+
|
|
1378
|
+
//Setup token in Authorization header
|
|
1379
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1380
|
+
|
|
1381
|
+
// setting up traceid
|
|
1382
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1383
|
+
|
|
1384
|
+
requestAPI.end(function (error, response) {
|
|
1385
|
+
if(error) {
|
|
1386
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1387
|
+
dfd.reject(err);
|
|
1388
|
+
}
|
|
1389
|
+
else { dfd.resolve(response.body); }
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
else {
|
|
1393
|
+
err = {};
|
|
1394
|
+
err.message = err.description = 'Mandatory param - classid not found in request options.';
|
|
1395
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1396
|
+
dfd.reject(err);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
return dfd.promise;
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
/* options = {
|
|
1403
|
+
"classid": "string", // required
|
|
1404
|
+
"assignedPathId" : "string", // required
|
|
1405
|
+
"productcode" : "string" //required
|
|
1406
|
+
};
|
|
1407
|
+
*/
|
|
1408
|
+
function getAssignedPathAnalytics(options) {
|
|
1409
|
+
var self = this;
|
|
1410
|
+
// Initializing promise
|
|
1411
|
+
var dfd = q.defer();
|
|
1412
|
+
var err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1413
|
+
if(err) { dfd.reject(err); }
|
|
1414
|
+
else {
|
|
1415
|
+
if(options && options.classid && options.assignedPathId && options.productcode) {
|
|
1416
|
+
// Passed all validations, Contruct API url
|
|
1417
|
+
var url = self.config.DEFAULT_HOSTS.ANALYTICS + self.config.ANALYTICS_API_URLS.getAssignedPathAnalytics;
|
|
1418
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1419
|
+
|
|
1420
|
+
var queryParams = {
|
|
1421
|
+
classid: options.classid,
|
|
1422
|
+
assignedpathid: options.assignedPathId,
|
|
1423
|
+
productcode: options.productcode
|
|
1424
|
+
};
|
|
1425
|
+
// Setup request with URL and Params
|
|
1426
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
1427
|
+
|
|
1428
|
+
//Setup token in Authorization header
|
|
1429
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1430
|
+
|
|
1431
|
+
// setting up traceid
|
|
1432
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1433
|
+
|
|
1434
|
+
requestAPI.end(function (error, response) {
|
|
1435
|
+
if(error) {
|
|
1436
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1437
|
+
dfd.reject(err);
|
|
1438
|
+
}
|
|
1439
|
+
else { dfd.resolve(response.body); }
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
else {
|
|
1443
|
+
err = {};
|
|
1444
|
+
err.message = err.description = 'Mandatory params - classid or assignedPathId or productcode not found in request options.';
|
|
1445
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1446
|
+
dfd.reject(err);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
return dfd.promise;
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
/* options = {
|
|
1453
|
+
"classid": "string", // required
|
|
1454
|
+
"userid" : "string", // required
|
|
1455
|
+
"progress" : "true/false",
|
|
1456
|
+
"group" : "true/false"
|
|
1457
|
+
};
|
|
1458
|
+
*/
|
|
1459
|
+
function getMyAssignedPathsOfClass(options) {
|
|
1460
|
+
var self = this;
|
|
1461
|
+
// Initializing promise
|
|
1462
|
+
var dfd = q.defer();
|
|
1463
|
+
var err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1464
|
+
if(err) { dfd.reject(err); }
|
|
1465
|
+
else {
|
|
1466
|
+
if(options && options.classid && options.userid ) {
|
|
1467
|
+
|
|
1468
|
+
// Passed all validations, Contruct API url
|
|
1469
|
+
var url = self.config.DEFAULT_HOSTS.ANALYTICS + self.config.ANALYTICS_API_URLS.getMyAssignedPathsOfClass;
|
|
1470
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1471
|
+
var queryParams = { userid: options.userid, classid: options.classid };
|
|
1472
|
+
if(options.progress) { queryParams.progress = options.progress; }
|
|
1473
|
+
if(options.group) { queryParams.group = options.group; }
|
|
1474
|
+
|
|
1475
|
+
// Setup request with URL and Params
|
|
1476
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
1477
|
+
//Setup token in Authorization header
|
|
1478
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1479
|
+
|
|
1480
|
+
// setting up traceid
|
|
1481
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1482
|
+
|
|
1483
|
+
requestAPI.end(function (error, response) {
|
|
1484
|
+
if(error) {
|
|
1485
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1486
|
+
dfd.reject(err);
|
|
1487
|
+
}
|
|
1488
|
+
else { dfd.resolve(response.body); }
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
else {
|
|
1492
|
+
err = {};
|
|
1493
|
+
err.message = err.description = 'Mandatory params - classid, userid not found in ' +
|
|
1494
|
+
'request options.';
|
|
1495
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1496
|
+
dfd.reject(err);
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
return dfd.promise;
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
/* options = {
|
|
1503
|
+
"classid": "string", // required
|
|
1504
|
+
"userid" : "string", // required
|
|
1505
|
+
"assignedPathId" : "string", // required
|
|
1506
|
+
"progress" : "true/false",
|
|
1507
|
+
"group" : "true/false"
|
|
1508
|
+
};
|
|
1509
|
+
*/
|
|
1510
|
+
function getMyParticularAssignedPathOfClass(options) {
|
|
1511
|
+
var self = this;
|
|
1512
|
+
// Initializing promise
|
|
1513
|
+
var dfd = q.defer();
|
|
1514
|
+
var err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
1515
|
+
if(err) { dfd.reject(err); }
|
|
1516
|
+
else {
|
|
1517
|
+
if(options && options.classid && options.userid && options.assignedPathId ) {
|
|
1518
|
+
|
|
1519
|
+
// Passed all validations, Contruct API url
|
|
1520
|
+
var url = self.config.DEFAULT_HOSTS.ANALYTICS + self.config.ANALYTICS_API_URLS.getMyAssignedPathsOfClass;
|
|
1521
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
1522
|
+
|
|
1523
|
+
var queryParams = {
|
|
1524
|
+
assignedpathid: options.assignedPathId, classid: options.classid, userid: options.userid
|
|
1525
|
+
};
|
|
1526
|
+
|
|
1527
|
+
if(options.progress) { queryParams.progress = options.progress; }
|
|
1528
|
+
if(options.group) { queryParams.group = options.group; }
|
|
1529
|
+
|
|
1530
|
+
// Setup request with URL and Params
|
|
1531
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
1532
|
+
//Setup token in Authorization header
|
|
1533
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
1534
|
+
|
|
1535
|
+
// setting up traceid
|
|
1536
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
1537
|
+
|
|
1538
|
+
requestAPI.end(function (error, response) {
|
|
1539
|
+
if(error) {
|
|
1540
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
1541
|
+
dfd.reject(err);
|
|
1542
|
+
}
|
|
1543
|
+
else { dfd.resolve(response.body); }
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
else {
|
|
1547
|
+
err = {};
|
|
1548
|
+
err.message = err.description = 'Mandatory params - classid, userid, assignedPathId not found in ' +
|
|
1549
|
+
'request options.';
|
|
1550
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
1551
|
+
dfd.reject(err);
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
return dfd.promise;
|
|
1555
|
+
}
|