-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (49 loc) · 1.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
/**
* @typedef {import('talentlms-sdk/src/classes/talent-opts')} TalentOpts
*/
const TalentLMSSdk = require('talentlms-sdk');
const getAllUsers = require('./src/talent/get-all-users.js');
const getCourse = require('./src/talent/get-course.js');
const types = {
group: require('./src/types/group.js')
};
class TalentLMSReports {
/**
* Generates a new instance of the Talent LMS reporting engine
*
* @param {TalentOpts} sdkOpts Options for instantiation of the talent sdk
*/
constructor(sdkOpts) {
this._sdk = new TalentLMSSdk(sdkOpts);
}
/**
* @typedef GenerateParams
* @property {('group')} type The type of report to generate. Other required parameters will
* differ depending on the provided type
* @property {string=} groupId Id of the group to generate reports for. Used with the 'group'
* report type
* @property {TalentLMSSdk=} sdk SDK to use for requests. Defaults to the sdk generated in
* construction of the TalentLMSReports object
*/
/**
* Generate a report
*
* @param {GenerateParams} params Parameters for report generation
*/
async generate(params) {
params = Object.assign({}, params, {sdk: this._sdk});
if (!types[params.type]) {
throw new Error(`Invalid TalentLMS Report type "${params.type}". Expected ${Object.keys(types).join(' or ')}`);
}
return types[params.type](params);
}
/**
* Clear the caches!
*/
clearCache() {
getAllUsers.clear();
getCourse.clear();
}
}
module.exports = TalentLMSReports;