@memberjunction/actions-bizapps-lms 5.3.1 → 5.4.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +26 -0
- package/LEARNWORLDS_SIDECAR_PLAN.md +845 -0
- package/dist/base/base-lms.action.d.ts +26 -4
- package/dist/base/base-lms.action.d.ts.map +1 -1
- package/dist/base/base-lms.action.js +73 -17
- package/dist/base/base-lms.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/attach-tags.action.d.ts +26 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.js +79 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/create-user.action.d.ts +24 -1
- package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/create-user.action.js +166 -142
- package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/detach-tags.action.d.ts +26 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.js +79 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts +31 -3
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/enroll-user.action.js +179 -125
- package/dist/providers/learnworlds/actions/enroll-user.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts +79 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.js +359 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.d.ts +34 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.js +107 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts +33 -2
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-certificates.action.js +311 -244
- package/dist/providers/learnworlds/actions/get-certificates.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts +14 -14
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js +234 -226
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts +42 -6
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-details.action.js +182 -148
- package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts +29 -82
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-courses.action.js +188 -207
- package/dist/providers/learnworlds/actions/get-courses.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts +22 -2
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js +316 -294
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts +23 -59
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-details.action.js +113 -114
- package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts +43 -5
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js +191 -147
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts +21 -92
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-progress.action.js +145 -166
- package/dist/providers/learnworlds/actions/get-user-progress.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-users.action.d.ts +14 -28
- package/dist/providers/learnworlds/actions/get-users.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-users.action.js +122 -143
- package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/index.d.ts +7 -0
- package/dist/providers/learnworlds/actions/index.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/index.js +7 -0
- package/dist/providers/learnworlds/actions/index.js.map +1 -1
- package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts +53 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.js +236 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/sso-login.action.d.ts +35 -0
- package/dist/providers/learnworlds/actions/sso-login.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/sso-login.action.js +101 -0
- package/dist/providers/learnworlds/actions/sso-login.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts +12 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.js +167 -210
- package/dist/providers/learnworlds/actions/update-user-progress.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/update-user.action.d.ts +39 -0
- package/dist/providers/learnworlds/actions/update-user.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/update-user.action.js +168 -0
- package/dist/providers/learnworlds/actions/update-user.action.js.map +1 -0
- package/dist/providers/learnworlds/index.d.ts +1 -0
- package/dist/providers/learnworlds/index.d.ts.map +1 -1
- package/dist/providers/learnworlds/index.js +2 -0
- package/dist/providers/learnworlds/index.js.map +1 -1
- package/dist/providers/learnworlds/interfaces/bundle.types.d.ts +16 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.d.ts +66 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/common.types.d.ts +221 -0
- package/dist/providers/learnworlds/interfaces/common.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/common.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/common.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/course.types.d.ts +393 -0
- package/dist/providers/learnworlds/interfaces/course.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/course.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/course.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts +165 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/index.d.ts +12 -0
- package/dist/providers/learnworlds/interfaces/index.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/index.js +13 -0
- package/dist/providers/learnworlds/interfaces/index.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts +39 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.d.ts +108 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/sso.types.d.ts +18 -0
- package/dist/providers/learnworlds/interfaces/sso.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/sso.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/sso.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/sync.types.d.ts +44 -0
- package/dist/providers/learnworlds/interfaces/sync.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/sync.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/sync.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/tag.types.d.ts +17 -0
- package/dist/providers/learnworlds/interfaces/tag.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/tag.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/tag.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/user.types.d.ts +198 -0
- package/dist/providers/learnworlds/interfaces/user.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/user.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/user.types.js.map +1 -0
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts +111 -7
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/learnworlds-base.action.js +293 -56
- package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -1
- package/package.json +8 -7
- package/src/__tests__/attach-tags.action.test.ts +137 -0
- package/src/__tests__/create-user.action.test.ts +311 -0
- package/src/__tests__/detach-tags.action.test.ts +136 -0
- package/src/__tests__/enroll-user.action.test.ts +283 -0
- package/src/__tests__/get-bulk-data.action.test.ts +649 -0
- package/src/__tests__/get-bundles.action.test.ts +215 -0
- package/src/__tests__/lms.test.ts +275 -184
- package/src/__tests__/onboard-learner.action.test.ts +455 -0
- package/src/__tests__/sso-login.action.test.ts +256 -0
- package/src/__tests__/update-user.action.test.ts +350 -0
- package/src/base/base-lms.action.ts +226 -163
- package/src/providers/learnworlds/actions/attach-tags.action.ts +90 -0
- package/src/providers/learnworlds/actions/create-user.action.ts +291 -235
- package/src/providers/learnworlds/actions/detach-tags.action.ts +90 -0
- package/src/providers/learnworlds/actions/enroll-user.action.ts +326 -220
- package/src/providers/learnworlds/actions/get-bulk-data.action.ts +438 -0
- package/src/providers/learnworlds/actions/get-bundles.action.ts +139 -0
- package/src/providers/learnworlds/actions/get-certificates.action.ts +499 -309
- package/src/providers/learnworlds/actions/get-course-analytics.action.ts +470 -337
- package/src/providers/learnworlds/actions/get-course-details.action.ts +395 -249
- package/src/providers/learnworlds/actions/get-courses.action.ts +508 -565
- package/src/providers/learnworlds/actions/get-quiz-results.action.ts +606 -381
- package/src/providers/learnworlds/actions/get-user-details.action.ts +335 -349
- package/src/providers/learnworlds/actions/get-user-enrollments.action.ts +328 -228
- package/src/providers/learnworlds/actions/get-user-progress.action.ts +522 -571
- package/src/providers/learnworlds/actions/get-users.action.ts +231 -282
- package/src/providers/learnworlds/actions/index.ts +8 -1
- package/src/providers/learnworlds/actions/onboard-learner.action.ts +286 -0
- package/src/providers/learnworlds/actions/sso-login.action.ts +116 -0
- package/src/providers/learnworlds/actions/update-user-progress.action.ts +301 -263
- package/src/providers/learnworlds/actions/update-user.action.ts +181 -0
- package/src/providers/learnworlds/index.ts +4 -1
- package/src/providers/learnworlds/interfaces/bundle.types.ts +17 -0
- package/src/providers/learnworlds/interfaces/certificate.types.ts +69 -0
- package/src/providers/learnworlds/interfaces/common.types.ts +233 -0
- package/src/providers/learnworlds/interfaces/course.types.ts +411 -0
- package/src/providers/learnworlds/interfaces/enrollment.types.ts +176 -0
- package/src/providers/learnworlds/interfaces/index.ts +12 -0
- package/src/providers/learnworlds/interfaces/onboarding.types.ts +41 -0
- package/src/providers/learnworlds/interfaces/quiz.types.ts +118 -0
- package/src/providers/learnworlds/interfaces/sso.types.ts +19 -0
- package/src/providers/learnworlds/interfaces/sync.types.ts +46 -0
- package/src/providers/learnworlds/interfaces/tag.types.ts +18 -0
- package/src/providers/learnworlds/interfaces/user.types.ts +204 -0
- package/src/providers/learnworlds/learnworlds-base.action.ts +468 -210
- package/tsconfig.json +1 -1
- package/dist/__tests__/lms.test.d.ts +0 -2
- package/dist/__tests__/lms.test.d.ts.map +0 -1
- package/dist/__tests__/lms.test.js +0 -232
- package/dist/__tests__/lms.test.js.map +0 -1
|
@@ -2,242 +2,342 @@ import { RegisterClass } from '@memberjunction/global';
|
|
|
2
2
|
import { LearnWorldsBaseAction } from '../learnworlds-base.action';
|
|
3
3
|
import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
4
4
|
import { BaseAction } from '@memberjunction/actions';
|
|
5
|
+
import { UserInfo } from '@memberjunction/core';
|
|
6
|
+
import { GetUserEnrollmentsParams, GetUserEnrollmentsResult, FormattedEnrollment, EnrollmentsSummary } from '../interfaces';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Raw API shape for a single enrollment from LearnWorlds
|
|
10
|
+
*/
|
|
11
|
+
interface LWApiEnrollmentData {
|
|
12
|
+
id?: string;
|
|
13
|
+
course_id?: string;
|
|
14
|
+
enrolled_at?: string;
|
|
15
|
+
created_at?: string;
|
|
16
|
+
starts_at?: string;
|
|
17
|
+
expires_at?: string;
|
|
18
|
+
status?: string;
|
|
19
|
+
progress_percentage?: number;
|
|
20
|
+
completed_units?: number;
|
|
21
|
+
total_units?: number;
|
|
22
|
+
completed_lessons?: number;
|
|
23
|
+
total_lessons?: number;
|
|
24
|
+
last_accessed_at?: string;
|
|
25
|
+
total_time_spent?: number;
|
|
26
|
+
grade?: number;
|
|
27
|
+
certificate_eligible?: boolean;
|
|
28
|
+
certificate_issued_at?: string;
|
|
29
|
+
completed_at?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Raw API shape for course details looked up per enrollment
|
|
34
|
+
*/
|
|
35
|
+
interface LWApiCourseBasic {
|
|
36
|
+
id?: string;
|
|
37
|
+
title?: string;
|
|
38
|
+
short_description?: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
image_url?: string;
|
|
41
|
+
level?: string;
|
|
42
|
+
duration?: number;
|
|
43
|
+
instructor_name?: string;
|
|
44
|
+
certificate_enabled?: boolean;
|
|
45
|
+
}
|
|
5
46
|
|
|
6
47
|
/**
|
|
7
48
|
* Action to retrieve all course enrollments for a specific user
|
|
8
49
|
*/
|
|
9
50
|
@RegisterClass(BaseAction, 'GetUserEnrollmentsAction')
|
|
10
51
|
export class GetUserEnrollmentsAction extends LearnWorldsBaseAction {
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
lastAccessedAt: enrollment.last_accessed_at,
|
|
78
|
-
totalTimeSpent: enrollment.total_time_spent || 0,
|
|
79
|
-
totalTimeSpentText: this.formatDuration(enrollment.total_time_spent || 0)
|
|
80
|
-
},
|
|
81
|
-
grade: enrollment.grade,
|
|
82
|
-
certificateEligible: enrollment.certificate_eligible || false,
|
|
83
|
-
certificateIssuedAt: enrollment.certificate_issued_at,
|
|
84
|
-
completedAt: enrollment.completed_at
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// Get course details if requested
|
|
88
|
-
if (includeCourseDetails && enrollment.course_id) {
|
|
89
|
-
try {
|
|
90
|
-
const course = await this.makeLearnWorldsRequest<any>(
|
|
91
|
-
`courses/${enrollment.course_id}`,
|
|
92
|
-
'GET',
|
|
93
|
-
undefined,
|
|
94
|
-
ContextUser
|
|
95
|
-
);
|
|
96
|
-
formattedEnrollment.course = {
|
|
97
|
-
id: course.id,
|
|
98
|
-
title: course.title,
|
|
99
|
-
description: course.short_description || course.description,
|
|
100
|
-
imageUrl: course.image_url,
|
|
101
|
-
level: course.level,
|
|
102
|
-
duration: course.duration,
|
|
103
|
-
durationText: this.formatDuration(course.duration),
|
|
104
|
-
instructorName: course.instructor_name,
|
|
105
|
-
certificateEnabled: course.certificate_enabled || false
|
|
106
|
-
};
|
|
107
|
-
} catch (error) {
|
|
108
|
-
// Log error but continue processing
|
|
109
|
-
console.warn(`Failed to get course details for ${enrollment.course_id}:`, error);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
formattedEnrollments.push(formattedEnrollment);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Calculate summary statistics
|
|
117
|
-
const totalEnrollments = formattedEnrollments.length;
|
|
118
|
-
const activeEnrollments = formattedEnrollments.filter(e => e.status === 'active').length;
|
|
119
|
-
const completedEnrollments = formattedEnrollments.filter(e =>
|
|
120
|
-
e.progress.percentage >= 100 || e.completedAt
|
|
121
|
-
).length;
|
|
122
|
-
const expiredEnrollments = formattedEnrollments.filter(e => e.status === 'expired').length;
|
|
123
|
-
const averageProgress = totalEnrollments > 0
|
|
124
|
-
? formattedEnrollments.reduce((sum, e) => sum + e.progress.percentage, 0) / totalEnrollments
|
|
125
|
-
: 0;
|
|
126
|
-
const totalTimeSpent = formattedEnrollments.reduce((sum, e) =>
|
|
127
|
-
sum + (e.progress.totalTimeSpent || 0), 0
|
|
128
|
-
);
|
|
129
|
-
const certificatesEarned = formattedEnrollments.filter(e => e.certificateIssuedAt).length;
|
|
130
|
-
|
|
131
|
-
// Create summary
|
|
132
|
-
const summary = {
|
|
133
|
-
userId: userId,
|
|
134
|
-
totalEnrollments: totalEnrollments,
|
|
135
|
-
activeEnrollments: activeEnrollments,
|
|
136
|
-
completedEnrollments: completedEnrollments,
|
|
137
|
-
expiredEnrollments: expiredEnrollments,
|
|
138
|
-
inProgressEnrollments: activeEnrollments - completedEnrollments,
|
|
139
|
-
averageProgressPercentage: Math.round(averageProgress * 100) / 100,
|
|
140
|
-
totalTimeSpent: totalTimeSpent,
|
|
141
|
-
totalTimeSpentText: this.formatDuration(totalTimeSpent),
|
|
142
|
-
certificatesEarned: certificatesEarned,
|
|
143
|
-
enrollmentsByStatus: {
|
|
144
|
-
active: activeEnrollments,
|
|
145
|
-
completed: completedEnrollments,
|
|
146
|
-
expired: expiredEnrollments
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
// Update output parameters
|
|
151
|
-
const outputParams = [...Params];
|
|
152
|
-
const enrollmentsParam = outputParams.find(p => p.Name === 'Enrollments');
|
|
153
|
-
if (enrollmentsParam) enrollmentsParam.Value = formattedEnrollments;
|
|
154
|
-
const totalCountParam = outputParams.find(p => p.Name === 'TotalCount');
|
|
155
|
-
if (totalCountParam) totalCountParam.Value = totalEnrollments;
|
|
156
|
-
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
157
|
-
if (summaryParam) summaryParam.Value = summary;
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
Success: true,
|
|
161
|
-
ResultCode: 'SUCCESS',
|
|
162
|
-
Message: `Retrieved ${totalEnrollments} enrollments for user`,
|
|
163
|
-
Params: outputParams
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
} catch (error) {
|
|
167
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
168
|
-
return {
|
|
169
|
-
Success: false,
|
|
170
|
-
ResultCode: 'ERROR',
|
|
171
|
-
Message: `Error retrieving enrollments: ${errorMessage}`,
|
|
172
|
-
Params
|
|
173
|
-
};
|
|
174
|
-
}
|
|
52
|
+
/**
|
|
53
|
+
* Metadata about this action
|
|
54
|
+
*/
|
|
55
|
+
public get Description(): string {
|
|
56
|
+
return 'Retrieves all course enrollments for a specific LearnWorlds user with detailed progress information';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Typed public method for direct (non-framework) callers.
|
|
61
|
+
* Sets company context, fetches enrollments, and returns a strongly-typed result.
|
|
62
|
+
* Throws on error.
|
|
63
|
+
*/
|
|
64
|
+
public async GetUserEnrollments(params: GetUserEnrollmentsParams, contextUser: UserInfo): Promise<GetUserEnrollmentsResult> {
|
|
65
|
+
this.SetCompanyContext(params.CompanyID);
|
|
66
|
+
|
|
67
|
+
const {
|
|
68
|
+
UserID: userId,
|
|
69
|
+
Status: status,
|
|
70
|
+
IncludeExpired: includeExpired = false,
|
|
71
|
+
IncludeCourseDetails: includeCourseDetails = true,
|
|
72
|
+
SortBy: sortBy = 'enrolled_at',
|
|
73
|
+
SortOrder: sortOrder = 'desc',
|
|
74
|
+
MaxResults: maxResults = 100,
|
|
75
|
+
} = params;
|
|
76
|
+
|
|
77
|
+
if (!userId) {
|
|
78
|
+
throw new Error('UserID is required');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.validatePathSegment(userId, 'UserID');
|
|
82
|
+
|
|
83
|
+
const queryParams = this.buildEnrollmentQueryParams(status, includeExpired, sortBy, sortOrder, maxResults);
|
|
84
|
+
|
|
85
|
+
const enrollmentsData = await this.makeLearnWorldsPaginatedRequest<LWApiEnrollmentData>(`users/${userId}/enrollments`, queryParams, contextUser);
|
|
86
|
+
|
|
87
|
+
const enrollments = enrollmentsData || [];
|
|
88
|
+
const formattedEnrollments = await this.formatEnrollments(enrollments, includeCourseDetails, contextUser);
|
|
89
|
+
|
|
90
|
+
const summary = this.calculateEnrollmentSummary(userId, formattedEnrollments);
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
Enrollments: formattedEnrollments,
|
|
94
|
+
TotalCount: formattedEnrollments.length,
|
|
95
|
+
Summary: summary,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Framework entry-point – thin wrapper around the typed public method.
|
|
101
|
+
*/
|
|
102
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
103
|
+
const { Params, ContextUser } = params;
|
|
104
|
+
this.params = Params;
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const typedParams = this.extractGetUserEnrollmentsParams(Params);
|
|
108
|
+
const result = await this.GetUserEnrollments(typedParams, ContextUser);
|
|
109
|
+
|
|
110
|
+
this.setOutputParam(Params, 'Enrollments', result.Enrollments);
|
|
111
|
+
this.setOutputParam(Params, 'TotalCount', result.TotalCount);
|
|
112
|
+
this.setOutputParam(Params, 'Summary', result.Summary);
|
|
113
|
+
|
|
114
|
+
return this.buildSuccessResult(`Retrieved ${result.TotalCount} enrollments for user`, Params);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
const msg = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
117
|
+
return this.buildErrorResult('ERROR', `Error retrieving enrollments: ${msg}`, Params);
|
|
175
118
|
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Extract typed params from framework ActionParam[]
|
|
123
|
+
*/
|
|
124
|
+
private extractGetUserEnrollmentsParams(params: ActionParam[]): GetUserEnrollmentsParams {
|
|
125
|
+
return {
|
|
126
|
+
CompanyID: this.getRequiredStringParam(params, 'CompanyID'),
|
|
127
|
+
UserID: this.getRequiredStringParam(params, 'UserID'),
|
|
128
|
+
Status: this.getOptionalStringParam(params, 'Status'),
|
|
129
|
+
IncludeExpired: this.getOptionalBooleanParam(params, 'IncludeExpired', false),
|
|
130
|
+
IncludeCourseDetails: this.getOptionalBooleanParam(params, 'IncludeCourseDetails', true),
|
|
131
|
+
SortBy: this.getOptionalStringParam(params, 'SortBy') || 'enrolled_at',
|
|
132
|
+
SortOrder: (this.getOptionalStringParam(params, 'SortOrder') || 'desc') as 'asc' | 'desc',
|
|
133
|
+
MaxResults: this.getOptionalNumberParam(params, 'MaxResults', LearnWorldsBaseAction.LW_MAX_PAGE_SIZE),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Build query parameters for the enrollments API request
|
|
139
|
+
*/
|
|
140
|
+
private buildEnrollmentQueryParams(
|
|
141
|
+
status: string | undefined,
|
|
142
|
+
includeExpired: boolean,
|
|
143
|
+
sortBy: string,
|
|
144
|
+
sortOrder: string,
|
|
145
|
+
maxResults: number,
|
|
146
|
+
): Record<string, string | number | boolean> {
|
|
147
|
+
const queryParams: Record<string, string | number | boolean> = {
|
|
148
|
+
limit: Math.min(maxResults, LearnWorldsBaseAction.LW_MAX_PAGE_SIZE),
|
|
149
|
+
sort: sortBy,
|
|
150
|
+
order: sortOrder,
|
|
151
|
+
};
|
|
176
152
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
*/
|
|
180
|
-
public get Params(): ActionParam[] {
|
|
181
|
-
const baseParams = this.getCommonLMSParams();
|
|
182
|
-
const specificParams: ActionParam[] = [
|
|
183
|
-
{
|
|
184
|
-
Name: 'UserID',
|
|
185
|
-
Type: 'Input',
|
|
186
|
-
Value: null
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
Name: 'Status',
|
|
190
|
-
Type: 'Input',
|
|
191
|
-
Value: null
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
Name: 'IncludeExpired',
|
|
195
|
-
Type: 'Input',
|
|
196
|
-
Value: false
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
Name: 'IncludeCourseDetails',
|
|
200
|
-
Type: 'Input',
|
|
201
|
-
Value: true
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
Name: 'SortBy',
|
|
205
|
-
Type: 'Input',
|
|
206
|
-
Value: 'enrolled_at'
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
Name: 'SortOrder',
|
|
210
|
-
Type: 'Input',
|
|
211
|
-
Value: 'desc'
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
Name: 'MaxResults',
|
|
215
|
-
Type: 'Input',
|
|
216
|
-
Value: 100
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
Name: 'Enrollments',
|
|
220
|
-
Type: 'Output',
|
|
221
|
-
Value: null
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
Name: 'TotalCount',
|
|
225
|
-
Type: 'Output',
|
|
226
|
-
Value: null
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
Name: 'Summary',
|
|
230
|
-
Type: 'Output',
|
|
231
|
-
Value: null
|
|
232
|
-
}
|
|
233
|
-
];
|
|
234
|
-
return [...baseParams, ...specificParams];
|
|
153
|
+
if (status) {
|
|
154
|
+
queryParams.status = status;
|
|
235
155
|
}
|
|
236
156
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
*/
|
|
240
|
-
public get Description(): string {
|
|
241
|
-
return 'Retrieves all course enrollments for a specific LearnWorlds user with detailed progress information';
|
|
157
|
+
if (!includeExpired) {
|
|
158
|
+
queryParams.hide_expired = true;
|
|
242
159
|
}
|
|
243
|
-
|
|
160
|
+
|
|
161
|
+
return queryParams;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Format all raw enrollments into typed FormattedEnrollment[].
|
|
166
|
+
* When course details are requested, fetches all unique courses in parallel
|
|
167
|
+
* and attaches results from a lookup map.
|
|
168
|
+
*/
|
|
169
|
+
private async formatEnrollments(enrollments: LWApiEnrollmentData[], includeCourseDetails: boolean, contextUser: UserInfo): Promise<FormattedEnrollment[]> {
|
|
170
|
+
// Build a course details map in one batch to avoid per-item API calls
|
|
171
|
+
const courseDetailsMap = includeCourseDetails
|
|
172
|
+
? await this.fetchCourseDetailsBatch(enrollments, contextUser)
|
|
173
|
+
: new Map<string, FormattedEnrollment['course']>();
|
|
174
|
+
|
|
175
|
+
return enrollments.map((enrollment) => {
|
|
176
|
+
const formatted = this.formatSingleEnrollment(enrollment);
|
|
177
|
+
if (includeCourseDetails && enrollment.course_id) {
|
|
178
|
+
formatted.course = courseDetailsMap.get(enrollment.course_id);
|
|
179
|
+
}
|
|
180
|
+
return formatted;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Fetch course details for all unique course IDs with controlled concurrency and return a lookup map.
|
|
186
|
+
*/
|
|
187
|
+
private async fetchCourseDetailsBatch(enrollments: LWApiEnrollmentData[], contextUser: UserInfo): Promise<Map<string, FormattedEnrollment['course']>> {
|
|
188
|
+
const uniqueCourseIds = [...new Set(enrollments.map((e) => e.course_id).filter((id): id is string => !!id))];
|
|
189
|
+
|
|
190
|
+
const results = await this.processInBatches(uniqueCourseIds, (courseId) => {
|
|
191
|
+
this.validatePathSegment(courseId, 'CourseID');
|
|
192
|
+
return this.fetchCourseDetailsForEnrollment(courseId, contextUser);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const map = new Map<string, FormattedEnrollment['course']>();
|
|
196
|
+
uniqueCourseIds.forEach((courseId, index) => {
|
|
197
|
+
map.set(courseId, results[index]);
|
|
198
|
+
});
|
|
199
|
+
return map;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Format a single raw enrollment to a FormattedEnrollment
|
|
204
|
+
*/
|
|
205
|
+
private formatSingleEnrollment(enrollment: LWApiEnrollmentData): FormattedEnrollment {
|
|
206
|
+
return {
|
|
207
|
+
id: enrollment.id || '',
|
|
208
|
+
courseId: enrollment.course_id || '',
|
|
209
|
+
enrolledAt: enrollment.enrolled_at || enrollment.created_at,
|
|
210
|
+
startsAt: enrollment.starts_at,
|
|
211
|
+
expiresAt: enrollment.expires_at,
|
|
212
|
+
status: enrollment.status || 'active',
|
|
213
|
+
progress: {
|
|
214
|
+
percentage: enrollment.progress_percentage || 0,
|
|
215
|
+
completedUnits: enrollment.completed_units || 0,
|
|
216
|
+
totalUnits: enrollment.total_units || 0,
|
|
217
|
+
completedLessons: enrollment.completed_lessons || 0,
|
|
218
|
+
totalLessons: enrollment.total_lessons || 0,
|
|
219
|
+
lastAccessedAt: enrollment.last_accessed_at,
|
|
220
|
+
totalTimeSpent: enrollment.total_time_spent || 0,
|
|
221
|
+
totalTimeSpentText: this.formatDuration(enrollment.total_time_spent || 0),
|
|
222
|
+
},
|
|
223
|
+
grade: enrollment.grade,
|
|
224
|
+
certificateEligible: enrollment.certificate_eligible || false,
|
|
225
|
+
certificateIssuedAt: enrollment.certificate_issued_at,
|
|
226
|
+
completedAt: enrollment.completed_at,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Fetch course details for a given enrollment's course ID
|
|
232
|
+
*/
|
|
233
|
+
private async fetchCourseDetailsForEnrollment(courseId: string, contextUser: UserInfo): Promise<FormattedEnrollment['course']> {
|
|
234
|
+
try {
|
|
235
|
+
const course = await this.makeLearnWorldsRequest<LWApiCourseBasic>(`courses/${courseId}`, 'GET', undefined, contextUser);
|
|
236
|
+
return {
|
|
237
|
+
id: course.id || courseId,
|
|
238
|
+
title: course.title || '',
|
|
239
|
+
description: course.short_description || course.description,
|
|
240
|
+
imageUrl: course.image_url,
|
|
241
|
+
level: course.level,
|
|
242
|
+
duration: course.duration,
|
|
243
|
+
durationText: this.formatDuration(course.duration || 0),
|
|
244
|
+
instructorName: course.instructor_name,
|
|
245
|
+
certificateEnabled: course.certificate_enabled || false,
|
|
246
|
+
};
|
|
247
|
+
} catch (error) {
|
|
248
|
+
console.warn(`Failed to get course details for ${courseId}:`, error);
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Calculate summary statistics from formatted enrollments
|
|
255
|
+
*/
|
|
256
|
+
private calculateEnrollmentSummary(userId: string, formattedEnrollments: FormattedEnrollment[]): EnrollmentsSummary {
|
|
257
|
+
const totalEnrollments = formattedEnrollments.length;
|
|
258
|
+
const activeEnrollments = formattedEnrollments.filter((e) => e.status === 'active').length;
|
|
259
|
+
const completedEnrollments = formattedEnrollments.filter((e) => e.progress.percentage >= 100 || e.completedAt).length;
|
|
260
|
+
const expiredEnrollments = formattedEnrollments.filter((e) => e.status === 'expired').length;
|
|
261
|
+
const averageProgress = totalEnrollments > 0 ? formattedEnrollments.reduce((sum, e) => sum + e.progress.percentage, 0) / totalEnrollments : 0;
|
|
262
|
+
const totalTimeSpent = formattedEnrollments.reduce((sum, e) => sum + (e.progress.totalTimeSpent || 0), 0);
|
|
263
|
+
const certificatesEarned = formattedEnrollments.filter((e) => e.certificateIssuedAt).length;
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
userId,
|
|
267
|
+
totalEnrollments,
|
|
268
|
+
activeEnrollments,
|
|
269
|
+
completedEnrollments,
|
|
270
|
+
expiredEnrollments,
|
|
271
|
+
inProgressEnrollments: Math.max(0, totalEnrollments - completedEnrollments - expiredEnrollments),
|
|
272
|
+
averageProgressPercentage: Math.round(averageProgress * 100) / 100,
|
|
273
|
+
totalTimeSpent,
|
|
274
|
+
totalTimeSpentText: this.formatDuration(totalTimeSpent),
|
|
275
|
+
certificatesEarned,
|
|
276
|
+
enrollmentsByStatus: {
|
|
277
|
+
active: activeEnrollments,
|
|
278
|
+
completed: completedEnrollments,
|
|
279
|
+
expired: expiredEnrollments,
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Define the parameters this action expects
|
|
286
|
+
*/
|
|
287
|
+
public get Params(): ActionParam[] {
|
|
288
|
+
const baseParams = this.getCommonLMSParams();
|
|
289
|
+
const specificParams: ActionParam[] = [
|
|
290
|
+
{
|
|
291
|
+
Name: 'UserID',
|
|
292
|
+
Type: 'Input',
|
|
293
|
+
Value: null,
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
Name: 'Status',
|
|
297
|
+
Type: 'Input',
|
|
298
|
+
Value: null,
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
Name: 'IncludeExpired',
|
|
302
|
+
Type: 'Input',
|
|
303
|
+
Value: false,
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
Name: 'IncludeCourseDetails',
|
|
307
|
+
Type: 'Input',
|
|
308
|
+
Value: true,
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
Name: 'SortBy',
|
|
312
|
+
Type: 'Input',
|
|
313
|
+
Value: 'enrolled_at',
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
Name: 'SortOrder',
|
|
317
|
+
Type: 'Input',
|
|
318
|
+
Value: 'desc',
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
Name: 'MaxResults',
|
|
322
|
+
Type: 'Input',
|
|
323
|
+
Value: 100,
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
Name: 'Enrollments',
|
|
327
|
+
Type: 'Output',
|
|
328
|
+
Value: null,
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
Name: 'TotalCount',
|
|
332
|
+
Type: 'Output',
|
|
333
|
+
Value: null,
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
Name: 'Summary',
|
|
337
|
+
Type: 'Output',
|
|
338
|
+
Value: null,
|
|
339
|
+
},
|
|
340
|
+
];
|
|
341
|
+
return [...baseParams, ...specificParams];
|
|
342
|
+
}
|
|
343
|
+
}
|