@memberjunction/actions-bizapps-lms 5.3.1 → 5.4.0
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 +16 -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,625 +2,576 @@ 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 {
|
|
7
|
+
GetUserProgressParams,
|
|
8
|
+
GetUserProgressResult,
|
|
9
|
+
CourseProgress,
|
|
10
|
+
UnitProgress,
|
|
11
|
+
LessonProgress,
|
|
12
|
+
UserLearningProgress,
|
|
13
|
+
LWApiProgressData,
|
|
14
|
+
} from '../interfaces';
|
|
5
15
|
|
|
6
16
|
/**
|
|
7
|
-
*
|
|
17
|
+
* Raw API shape for a user info response (subset needed here)
|
|
8
18
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
courseTitle: string;
|
|
12
|
-
enrollmentId: string;
|
|
13
|
-
enrolledAt: Date;
|
|
14
|
-
lastAccessedAt?: Date;
|
|
15
|
-
|
|
16
|
-
// Progress metrics
|
|
17
|
-
progressPercentage: number;
|
|
18
|
-
completedUnits: number;
|
|
19
|
-
totalUnits: number;
|
|
20
|
-
completedLessons: number;
|
|
21
|
-
totalLessons: number;
|
|
22
|
-
|
|
23
|
-
// Time metrics
|
|
24
|
-
totalTimeSpent: number;
|
|
25
|
-
averageSessionTime: number;
|
|
26
|
-
estimatedTimeToComplete?: number;
|
|
27
|
-
|
|
28
|
-
// Performance metrics
|
|
29
|
-
quizScoreAverage?: number;
|
|
30
|
-
assignmentsCompleted?: number;
|
|
31
|
-
assignmentsTotal?: number;
|
|
32
|
-
currentGrade?: number;
|
|
33
|
-
|
|
34
|
-
// Status
|
|
35
|
-
status: 'not_started' | 'in_progress' | 'completed' | 'expired';
|
|
36
|
-
completedAt?: Date;
|
|
37
|
-
expiresAt?: Date;
|
|
38
|
-
certificateEarned: boolean;
|
|
39
|
-
certificateUrl?: string;
|
|
40
|
-
|
|
41
|
-
// Unit-level progress
|
|
42
|
-
unitProgress?: UnitProgress[];
|
|
19
|
+
interface LWApiUserInfo {
|
|
20
|
+
email?: string;
|
|
43
21
|
}
|
|
44
22
|
|
|
45
23
|
/**
|
|
46
|
-
*
|
|
24
|
+
* Raw API shape for progress data coming back from LearnWorlds
|
|
47
25
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
26
|
+
interface LWApiCourseProgressResponse {
|
|
27
|
+
course_id?: string;
|
|
28
|
+
course?: { id?: string; title?: string };
|
|
29
|
+
course_title?: string;
|
|
30
|
+
enrollment_id?: string;
|
|
31
|
+
id?: string;
|
|
32
|
+
enrolled_at?: string | number;
|
|
33
|
+
created?: string | number;
|
|
34
|
+
last_accessed_at?: string | number;
|
|
35
|
+
progress?: LWApiProgressData;
|
|
36
|
+
completed_lessons?: number;
|
|
37
|
+
total_lessons?: number;
|
|
38
|
+
average_session_time?: number;
|
|
39
|
+
estimated_time_to_complete?: number;
|
|
40
|
+
total_time_spent?: number;
|
|
41
|
+
progress_percentage?: number;
|
|
42
|
+
quiz_score_average?: number;
|
|
43
|
+
assignments_completed?: number;
|
|
44
|
+
assignments_total?: number;
|
|
45
|
+
current_grade?: number;
|
|
46
|
+
grade?: number;
|
|
47
|
+
completed?: boolean;
|
|
48
|
+
completed_at?: string | number;
|
|
49
|
+
expired?: boolean;
|
|
50
|
+
expires_at?: string | number;
|
|
51
|
+
started?: boolean;
|
|
52
|
+
certificate_earned?: boolean;
|
|
53
|
+
certificate_url?: string;
|
|
54
|
+
percentage?: number;
|
|
55
|
+
completed_units?: number;
|
|
56
|
+
total_units?: number;
|
|
57
|
+
time_spent?: number;
|
|
67
58
|
}
|
|
68
59
|
|
|
69
60
|
/**
|
|
70
|
-
*
|
|
61
|
+
* Raw API shape for a unit
|
|
71
62
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
videoWatchTime?: number;
|
|
90
|
-
videoTotalTime?: number;
|
|
91
|
-
quizScore?: number;
|
|
92
|
-
quizMaxScore?: number;
|
|
93
|
-
quizAttempts?: number;
|
|
94
|
-
assignmentSubmitted?: boolean;
|
|
95
|
-
assignmentGrade?: number;
|
|
63
|
+
interface LWApiUnitData {
|
|
64
|
+
id?: string;
|
|
65
|
+
unit_id?: string;
|
|
66
|
+
title?: string;
|
|
67
|
+
name?: string;
|
|
68
|
+
type?: string;
|
|
69
|
+
order?: number;
|
|
70
|
+
position?: number;
|
|
71
|
+
progress_percentage?: number;
|
|
72
|
+
completed_lessons?: number;
|
|
73
|
+
total_lessons?: number;
|
|
74
|
+
time_spent?: number;
|
|
75
|
+
completed?: boolean;
|
|
76
|
+
started?: boolean;
|
|
77
|
+
started_at?: string | number;
|
|
78
|
+
completed_at?: string | number;
|
|
79
|
+
lessons?: LWApiLessonData[];
|
|
96
80
|
}
|
|
97
81
|
|
|
98
82
|
/**
|
|
99
|
-
*
|
|
83
|
+
* Raw API shape for a lesson
|
|
100
84
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
85
|
+
interface LWApiLessonData {
|
|
86
|
+
id?: string;
|
|
87
|
+
lesson_id?: string;
|
|
88
|
+
title?: string;
|
|
89
|
+
name?: string;
|
|
90
|
+
type?: string;
|
|
91
|
+
order?: number;
|
|
92
|
+
position?: number;
|
|
93
|
+
completed?: boolean;
|
|
94
|
+
progress_percentage?: number;
|
|
95
|
+
time_spent?: number;
|
|
96
|
+
started_at?: string | number;
|
|
97
|
+
completed_at?: string | number;
|
|
98
|
+
last_accessed_at?: string | number;
|
|
99
|
+
video_watch_time?: number;
|
|
100
|
+
video_total_time?: number;
|
|
101
|
+
quiz_score?: number;
|
|
102
|
+
quiz_max_score?: number;
|
|
103
|
+
quiz_attempts?: number;
|
|
104
|
+
assignment_submitted?: boolean;
|
|
105
|
+
assignment_grade?: number;
|
|
119
106
|
}
|
|
120
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Raw API shape for enrollment list items
|
|
110
|
+
*/
|
|
111
|
+
interface LWApiEnrollmentItem {
|
|
112
|
+
course_id?: string;
|
|
113
|
+
course?: { id?: string };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
type LessonType = 'video' | 'text' | 'quiz' | 'assignment' | 'scorm' | 'interactive';
|
|
117
|
+
|
|
121
118
|
/**
|
|
122
119
|
* Action to retrieve detailed progress information for a LearnWorlds user
|
|
123
120
|
*/
|
|
124
121
|
@RegisterClass(BaseAction, 'GetLearnWorldsUserProgressAction')
|
|
125
122
|
export class GetLearnWorldsUserProgressAction extends LearnWorldsBaseAction {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Description of the action
|
|
125
|
+
*/
|
|
126
|
+
public get Description(): string {
|
|
127
|
+
return 'Retrieves comprehensive learning progress for a user in LearnWorlds, including course completion, time spent, and detailed unit/lesson progress';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Typed public method for direct (non-framework) callers.
|
|
132
|
+
* Sets company context, fetches progress, and returns a strongly-typed result.
|
|
133
|
+
* Throws on error.
|
|
134
|
+
*/
|
|
135
|
+
public async GetUserProgress(params: GetUserProgressParams, contextUser: UserInfo): Promise<GetUserProgressResult> {
|
|
136
|
+
this.SetCompanyContext(params.CompanyID);
|
|
137
|
+
|
|
138
|
+
const { UserID: userId, CourseID: courseId, IncludeUnitDetails: includeUnitDetails = false, IncludeLessonDetails: includeLessonDetails = false } = params;
|
|
139
|
+
|
|
140
|
+
if (!userId) {
|
|
141
|
+
throw new Error('UserID parameter is required');
|
|
132
142
|
}
|
|
133
143
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
138
|
-
try {
|
|
139
|
-
const contextUser = params.ContextUser;
|
|
140
|
-
if (!contextUser) {
|
|
141
|
-
return {
|
|
142
|
-
Success: false,
|
|
143
|
-
ResultCode: 'ERROR',
|
|
144
|
-
Message: 'Context user is required for LearnWorlds API calls'
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Store params for base class methods
|
|
149
|
-
this.params = params.Params;
|
|
150
|
-
|
|
151
|
-
// Get user ID
|
|
152
|
-
const userId = this.getParamValue(params.Params, 'UserID');
|
|
153
|
-
if (!userId) {
|
|
154
|
-
return {
|
|
155
|
-
Success: false,
|
|
156
|
-
ResultCode: 'ERROR',
|
|
157
|
-
Message: 'UserID parameter is required'
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Optional course ID for specific course progress
|
|
162
|
-
const courseId = this.getParamValue(params.Params, 'CourseID');
|
|
163
|
-
const includeUnitDetails = this.getParamValue(params.Params, 'IncludeUnitDetails') ?? false;
|
|
164
|
-
const includeLessonDetails = this.getParamValue(params.Params, 'IncludeLessonDetails') ?? false;
|
|
165
|
-
|
|
166
|
-
let userProgress: UserLearningProgress;
|
|
167
|
-
|
|
168
|
-
if (courseId) {
|
|
169
|
-
// Get progress for specific course
|
|
170
|
-
const courseProgress = await this.getCourseProgress(userId, courseId, includeUnitDetails, includeLessonDetails, contextUser);
|
|
171
|
-
|
|
172
|
-
// Create user progress object with single course
|
|
173
|
-
userProgress = {
|
|
174
|
-
userId,
|
|
175
|
-
userEmail: '', // Will be populated if we get user info
|
|
176
|
-
totalCourses: 1,
|
|
177
|
-
coursesCompleted: courseProgress.status === 'completed' ? 1 : 0,
|
|
178
|
-
coursesInProgress: courseProgress.status === 'in_progress' ? 1 : 0,
|
|
179
|
-
coursesNotStarted: courseProgress.status === 'not_started' ? 1 : 0,
|
|
180
|
-
overallProgressPercentage: courseProgress.progressPercentage,
|
|
181
|
-
totalTimeSpent: courseProgress.totalTimeSpent,
|
|
182
|
-
totalCertificatesEarned: courseProgress.certificateEarned ? 1 : 0,
|
|
183
|
-
courses: [courseProgress]
|
|
184
|
-
};
|
|
185
|
-
} else {
|
|
186
|
-
// Get progress for all courses
|
|
187
|
-
userProgress = await this.getAllCoursesProgress(userId, includeUnitDetails, includeLessonDetails, contextUser);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Try to get user email
|
|
191
|
-
try {
|
|
192
|
-
const userInfo = await this.makeLearnWorldsRequest<any>(
|
|
193
|
-
`users/${userId}`,
|
|
194
|
-
'GET',
|
|
195
|
-
undefined,
|
|
196
|
-
contextUser
|
|
197
|
-
);
|
|
198
|
-
userProgress.userEmail = userInfo.email || '';
|
|
199
|
-
} catch {
|
|
200
|
-
// Ignore if we can't get user info
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Calculate analytics
|
|
204
|
-
this.calculateLearningAnalytics(userProgress);
|
|
205
|
-
|
|
206
|
-
// Create output parameters
|
|
207
|
-
if (!params.Params.find(p => p.Name === 'UserProgress')) {
|
|
208
|
-
params.Params.push({
|
|
209
|
-
Name: 'UserProgress',
|
|
210
|
-
Type: 'Output',
|
|
211
|
-
Value: userProgress
|
|
212
|
-
});
|
|
213
|
-
} else {
|
|
214
|
-
params.Params.find(p => p.Name === 'UserProgress')!.Value = userProgress;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (!params.Params.find(p => p.Name === 'Summary')) {
|
|
218
|
-
params.Params.push({
|
|
219
|
-
Name: 'Summary',
|
|
220
|
-
Type: 'Output',
|
|
221
|
-
Value: this.createProgressSummary(userProgress)
|
|
222
|
-
});
|
|
223
|
-
} else {
|
|
224
|
-
params.Params.find(p => p.Name === 'Summary')!.Value = this.createProgressSummary(userProgress);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
Success: true,
|
|
229
|
-
ResultCode: 'SUCCESS',
|
|
230
|
-
Message: courseId ?
|
|
231
|
-
`Successfully retrieved progress for course ${courseId}` :
|
|
232
|
-
`Successfully retrieved progress for ${userProgress.totalCourses} courses`
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
} catch (error) {
|
|
236
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
237
|
-
return {
|
|
238
|
-
Success: false,
|
|
239
|
-
ResultCode: 'ERROR',
|
|
240
|
-
Message: errorMessage
|
|
241
|
-
};
|
|
242
|
-
}
|
|
144
|
+
this.validatePathSegment(userId, 'UserID');
|
|
145
|
+
if (courseId) {
|
|
146
|
+
this.validatePathSegment(courseId, 'CourseID');
|
|
243
147
|
}
|
|
244
148
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
// Get unit-level details if requested
|
|
266
|
-
if (includeUnits) {
|
|
267
|
-
try {
|
|
268
|
-
const unitsResponse = await this.makeLearnWorldsRequest<{
|
|
269
|
-
data: any[]
|
|
270
|
-
}>(
|
|
271
|
-
`users/${userId}/courses/${courseId}/units`,
|
|
272
|
-
'GET',
|
|
273
|
-
undefined,
|
|
274
|
-
contextUser
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
if (unitsResponse.data) {
|
|
278
|
-
progress.unitProgress = await Promise.all(
|
|
279
|
-
unitsResponse.data.map(unit =>
|
|
280
|
-
this.mapUnitProgress(unit, userId, courseId, includeLessons, contextUser)
|
|
281
|
-
)
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
} catch {
|
|
285
|
-
// Units endpoint might not be available
|
|
286
|
-
}
|
|
287
|
-
}
|
|
149
|
+
let userProgress: UserLearningProgress;
|
|
150
|
+
|
|
151
|
+
if (courseId) {
|
|
152
|
+
const courseProgress = await this.getCourseProgress(userId, courseId, includeUnitDetails, includeLessonDetails, contextUser);
|
|
153
|
+
|
|
154
|
+
userProgress = {
|
|
155
|
+
userId,
|
|
156
|
+
userEmail: '',
|
|
157
|
+
totalCourses: 1,
|
|
158
|
+
coursesCompleted: courseProgress.status === 'completed' ? 1 : 0,
|
|
159
|
+
coursesInProgress: courseProgress.status === 'in_progress' ? 1 : 0,
|
|
160
|
+
coursesNotStarted: courseProgress.status === 'not_started' ? 1 : 0,
|
|
161
|
+
overallProgressPercentage: courseProgress.progressPercentage,
|
|
162
|
+
totalTimeSpent: courseProgress.totalTimeSpent,
|
|
163
|
+
totalCertificatesEarned: courseProgress.certificateEarned ? 1 : 0,
|
|
164
|
+
courses: [courseProgress],
|
|
165
|
+
};
|
|
166
|
+
} else {
|
|
167
|
+
userProgress = await this.getAllCoursesProgress(userId, includeUnitDetails, includeLessonDetails, contextUser);
|
|
168
|
+
}
|
|
288
169
|
|
|
289
|
-
|
|
170
|
+
// Try to get user email
|
|
171
|
+
try {
|
|
172
|
+
const userInfo = await this.makeLearnWorldsRequest<LWApiUserInfo>(`users/${userId}`, 'GET', undefined, contextUser);
|
|
173
|
+
userProgress.userEmail = userInfo.email || '';
|
|
174
|
+
} catch {
|
|
175
|
+
// Ignore if we can't get user info
|
|
290
176
|
}
|
|
291
177
|
|
|
292
|
-
|
|
293
|
-
* Get progress for all user courses
|
|
294
|
-
*/
|
|
295
|
-
private async getAllCoursesProgress(
|
|
296
|
-
userId: string,
|
|
297
|
-
includeUnits: boolean,
|
|
298
|
-
includeLessons: boolean,
|
|
299
|
-
contextUser: any
|
|
300
|
-
): Promise<UserLearningProgress> {
|
|
301
|
-
// Get all enrollments
|
|
302
|
-
const enrollmentsResponse = await this.makeLearnWorldsRequest<{
|
|
303
|
-
data: any[]
|
|
304
|
-
}>(
|
|
305
|
-
`users/${userId}/enrollments`,
|
|
306
|
-
'GET',
|
|
307
|
-
undefined,
|
|
308
|
-
contextUser
|
|
309
|
-
);
|
|
178
|
+
this.calculateLearningAnalytics(userProgress);
|
|
310
179
|
|
|
311
|
-
|
|
312
|
-
this.getCourseProgress(
|
|
313
|
-
userId,
|
|
314
|
-
enrollment.course_id || enrollment.course?.id,
|
|
315
|
-
includeUnits,
|
|
316
|
-
includeLessons,
|
|
317
|
-
contextUser
|
|
318
|
-
).catch(() => null) // Handle individual course failures gracefully
|
|
319
|
-
);
|
|
180
|
+
const summary = this.createProgressSummary(userProgress);
|
|
320
181
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const inProgress = validCourses.filter(c => c.status === 'in_progress').length;
|
|
327
|
-
const notStarted = validCourses.filter(c => c.status === 'not_started').length;
|
|
328
|
-
const totalTime = validCourses.reduce((sum, c) => sum + c.totalTimeSpent, 0);
|
|
329
|
-
const totalCerts = validCourses.filter(c => c.certificateEarned).length;
|
|
330
|
-
|
|
331
|
-
// Calculate overall progress
|
|
332
|
-
let overallProgress = 0;
|
|
333
|
-
if (validCourses.length > 0) {
|
|
334
|
-
const totalProgress = validCourses.reduce((sum, c) => sum + c.progressPercentage, 0);
|
|
335
|
-
overallProgress = Math.round(totalProgress / validCourses.length);
|
|
336
|
-
}
|
|
182
|
+
return {
|
|
183
|
+
UserProgress: userProgress,
|
|
184
|
+
Summary: summary,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
337
187
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
return {
|
|
345
|
-
userId,
|
|
346
|
-
userEmail: '',
|
|
347
|
-
totalCourses: validCourses.length,
|
|
348
|
-
coursesCompleted: completed,
|
|
349
|
-
coursesInProgress: inProgress,
|
|
350
|
-
coursesNotStarted: notStarted,
|
|
351
|
-
overallProgressPercentage: overallProgress,
|
|
352
|
-
totalTimeSpent: totalTime,
|
|
353
|
-
totalCertificatesEarned: totalCerts,
|
|
354
|
-
averageQuizScore: avgQuizScore,
|
|
355
|
-
courses: validCourses
|
|
356
|
-
};
|
|
357
|
-
}
|
|
188
|
+
/**
|
|
189
|
+
* Framework entry-point – thin wrapper around the typed public method.
|
|
190
|
+
*/
|
|
191
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
192
|
+
const { Params, ContextUser } = params;
|
|
193
|
+
this.params = Params;
|
|
358
194
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
private mapCourseProgress(data: any): CourseProgress {
|
|
363
|
-
const progress = this.calculateProgress(data.progress || data);
|
|
364
|
-
const status = this.determineCourseStatus(data);
|
|
365
|
-
|
|
366
|
-
return {
|
|
367
|
-
courseId: data.course_id || data.course?.id,
|
|
368
|
-
courseTitle: data.course_title || data.course?.title || 'Unknown Course',
|
|
369
|
-
enrollmentId: data.enrollment_id || data.id,
|
|
370
|
-
enrolledAt: this.parseLearnWorldsDate(data.enrolled_at || data.created),
|
|
371
|
-
lastAccessedAt: data.last_accessed_at ? this.parseLearnWorldsDate(data.last_accessed_at) : undefined,
|
|
372
|
-
|
|
373
|
-
progressPercentage: progress.percentage,
|
|
374
|
-
completedUnits: progress.completedUnits,
|
|
375
|
-
totalUnits: progress.totalUnits,
|
|
376
|
-
completedLessons: data.completed_lessons || 0,
|
|
377
|
-
totalLessons: data.total_lessons || 0,
|
|
378
|
-
|
|
379
|
-
totalTimeSpent: progress.timeSpent,
|
|
380
|
-
averageSessionTime: data.average_session_time || 0,
|
|
381
|
-
estimatedTimeToComplete: this.calculateEstimatedTimeToComplete(data),
|
|
382
|
-
|
|
383
|
-
quizScoreAverage: data.quiz_score_average,
|
|
384
|
-
assignmentsCompleted: data.assignments_completed,
|
|
385
|
-
assignmentsTotal: data.assignments_total,
|
|
386
|
-
currentGrade: data.current_grade || data.grade,
|
|
387
|
-
|
|
388
|
-
status,
|
|
389
|
-
completedAt: data.completed_at ? this.parseLearnWorldsDate(data.completed_at) : undefined,
|
|
390
|
-
expiresAt: data.expires_at ? this.parseLearnWorldsDate(data.expires_at) : undefined,
|
|
391
|
-
certificateEarned: data.certificate_earned || false,
|
|
392
|
-
certificateUrl: data.certificate_url
|
|
393
|
-
};
|
|
394
|
-
}
|
|
195
|
+
try {
|
|
196
|
+
const typedParams = this.extractGetUserProgressParams(Params);
|
|
197
|
+
const result = await this.GetUserProgress(typedParams, ContextUser);
|
|
395
198
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
*/
|
|
399
|
-
private async mapUnitProgress(
|
|
400
|
-
unitData: any,
|
|
401
|
-
userId: string,
|
|
402
|
-
courseId: string,
|
|
403
|
-
includeLessons: boolean,
|
|
404
|
-
contextUser: any
|
|
405
|
-
): Promise<UnitProgress> {
|
|
406
|
-
const unitProgress: UnitProgress = {
|
|
407
|
-
unitId: unitData.id || unitData.unit_id,
|
|
408
|
-
unitTitle: unitData.title || unitData.name,
|
|
409
|
-
unitType: unitData.type || 'section',
|
|
410
|
-
order: unitData.order || unitData.position || 0,
|
|
411
|
-
|
|
412
|
-
progressPercentage: unitData.progress_percentage || 0,
|
|
413
|
-
completedLessons: unitData.completed_lessons || 0,
|
|
414
|
-
totalLessons: unitData.total_lessons || 0,
|
|
415
|
-
timeSpent: unitData.time_spent || 0,
|
|
416
|
-
|
|
417
|
-
status: this.determineUnitStatus(unitData),
|
|
418
|
-
startedAt: unitData.started_at ? this.parseLearnWorldsDate(unitData.started_at) : undefined,
|
|
419
|
-
completedAt: unitData.completed_at ? this.parseLearnWorldsDate(unitData.completed_at) : undefined
|
|
420
|
-
};
|
|
421
|
-
|
|
422
|
-
// Get lesson details if requested
|
|
423
|
-
if (includeLessons && unitData.lessons) {
|
|
424
|
-
unitProgress.lessons = unitData.lessons.map((lesson: any) => this.mapLessonProgress(lesson));
|
|
425
|
-
}
|
|
199
|
+
this.setOutputParam(Params, 'UserProgress', result.UserProgress);
|
|
200
|
+
this.setOutputParam(Params, 'Summary', result.Summary);
|
|
426
201
|
|
|
427
|
-
|
|
428
|
-
|
|
202
|
+
const courseId = typedParams.CourseID;
|
|
203
|
+
const message = courseId
|
|
204
|
+
? `Successfully retrieved progress for course ${courseId}`
|
|
205
|
+
: `Successfully retrieved progress for ${result.UserProgress.totalCourses} courses`;
|
|
429
206
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
return {
|
|
435
|
-
lessonId: lessonData.id || lessonData.lesson_id,
|
|
436
|
-
lessonTitle: lessonData.title || lessonData.name,
|
|
437
|
-
lessonType: this.mapLessonType(lessonData.type),
|
|
438
|
-
order: lessonData.order || lessonData.position || 0,
|
|
439
|
-
|
|
440
|
-
completed: lessonData.completed || false,
|
|
441
|
-
progressPercentage: lessonData.progress_percentage || (lessonData.completed ? 100 : 0),
|
|
442
|
-
timeSpent: lessonData.time_spent || 0,
|
|
443
|
-
|
|
444
|
-
startedAt: lessonData.started_at ? this.parseLearnWorldsDate(lessonData.started_at) : undefined,
|
|
445
|
-
completedAt: lessonData.completed_at ? this.parseLearnWorldsDate(lessonData.completed_at) : undefined,
|
|
446
|
-
lastAccessedAt: lessonData.last_accessed_at ? this.parseLearnWorldsDate(lessonData.last_accessed_at) : undefined,
|
|
447
|
-
|
|
448
|
-
videoWatchTime: lessonData.video_watch_time,
|
|
449
|
-
videoTotalTime: lessonData.video_total_time,
|
|
450
|
-
quizScore: lessonData.quiz_score,
|
|
451
|
-
quizMaxScore: lessonData.quiz_max_score,
|
|
452
|
-
quizAttempts: lessonData.quiz_attempts,
|
|
453
|
-
assignmentSubmitted: lessonData.assignment_submitted,
|
|
454
|
-
assignmentGrade: lessonData.assignment_grade
|
|
455
|
-
};
|
|
207
|
+
return this.buildSuccessResult(message, Params);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
const msg = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
210
|
+
return this.buildErrorResult('ERROR', msg, Params);
|
|
456
211
|
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Extract typed params from framework ActionParam[]
|
|
216
|
+
*/
|
|
217
|
+
private extractGetUserProgressParams(params: ActionParam[]): GetUserProgressParams {
|
|
218
|
+
return {
|
|
219
|
+
CompanyID: this.getRequiredStringParam(params, 'CompanyID'),
|
|
220
|
+
UserID: this.getRequiredStringParam(params, 'UserID'),
|
|
221
|
+
CourseID: this.getOptionalStringParam(params, 'CourseID'),
|
|
222
|
+
IncludeUnitDetails: this.getOptionalBooleanParam(params, 'IncludeUnitDetails', false),
|
|
223
|
+
IncludeLessonDetails: this.getOptionalBooleanParam(params, 'IncludeLessonDetails', false),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Get progress for a specific course
|
|
229
|
+
*/
|
|
230
|
+
private async getCourseProgress(
|
|
231
|
+
userId: string,
|
|
232
|
+
courseId: string,
|
|
233
|
+
includeUnits: boolean,
|
|
234
|
+
includeLessons: boolean,
|
|
235
|
+
contextUser: UserInfo,
|
|
236
|
+
): Promise<CourseProgress> {
|
|
237
|
+
const progressResponse = await this.makeLearnWorldsRequest<LWApiCourseProgressResponse>(
|
|
238
|
+
`users/${userId}/courses/${courseId}/progress`,
|
|
239
|
+
'GET',
|
|
240
|
+
undefined,
|
|
241
|
+
contextUser,
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const progress = this.mapCourseProgress(progressResponse);
|
|
245
|
+
|
|
246
|
+
if (includeUnits) {
|
|
247
|
+
try {
|
|
248
|
+
const unitsResponse = await this.makeLearnWorldsRequest<{ data: LWApiUnitData[] }>(
|
|
249
|
+
`users/${userId}/courses/${courseId}/units`,
|
|
250
|
+
'GET',
|
|
251
|
+
undefined,
|
|
252
|
+
contextUser,
|
|
253
|
+
);
|
|
457
254
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
*/
|
|
461
|
-
private determineCourseStatus(data: any): 'not_started' | 'in_progress' | 'completed' | 'expired' {
|
|
462
|
-
if (data.expired || (data.expires_at && new Date(data.expires_at) < new Date())) {
|
|
463
|
-
return 'expired';
|
|
255
|
+
if (unitsResponse.data) {
|
|
256
|
+
progress.unitProgress = await Promise.all(unitsResponse.data.map((unit) => this.mapUnitProgress(unit, includeLessons)));
|
|
464
257
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
if (data.progress_percentage > 0 || data.started) {
|
|
469
|
-
return 'in_progress';
|
|
470
|
-
}
|
|
471
|
-
return 'not_started';
|
|
258
|
+
} catch {
|
|
259
|
+
// Units endpoint might not be available
|
|
260
|
+
}
|
|
472
261
|
}
|
|
473
262
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
263
|
+
return progress;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Get progress for all user courses
|
|
268
|
+
*/
|
|
269
|
+
private async getAllCoursesProgress(userId: string, includeUnits: boolean, includeLessons: boolean, contextUser: UserInfo): Promise<UserLearningProgress> {
|
|
270
|
+
const enrollmentsResponse = await this.makeLearnWorldsRequest<{ data: LWApiEnrollmentItem[] }>(
|
|
271
|
+
`users/${userId}/enrollments`,
|
|
272
|
+
'GET',
|
|
273
|
+
undefined,
|
|
274
|
+
contextUser,
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
const courseProgressResults = await this.processInBatches(enrollmentsResponse.data, (enrollment) =>
|
|
278
|
+
this.getCourseProgress(userId, enrollment.course_id || enrollment.course?.id || '', includeUnits, includeLessons, contextUser).catch(() => null),
|
|
279
|
+
);
|
|
280
|
+
const validCourses = courseProgressResults.filter((p): p is CourseProgress => p !== null);
|
|
281
|
+
|
|
282
|
+
return this.aggregateCourseProgress(userId, validCourses);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Aggregate individual course progress into overall user learning progress
|
|
287
|
+
*/
|
|
288
|
+
private aggregateCourseProgress(userId: string, validCourses: CourseProgress[]): UserLearningProgress {
|
|
289
|
+
const completed = validCourses.filter((c) => c.status === 'completed').length;
|
|
290
|
+
const inProgress = validCourses.filter((c) => c.status === 'in_progress').length;
|
|
291
|
+
const notStarted = validCourses.filter((c) => c.status === 'not_started').length;
|
|
292
|
+
const totalTime = validCourses.reduce((sum, c) => sum + c.totalTimeSpent, 0);
|
|
293
|
+
const totalCerts = validCourses.filter((c) => c.certificateEarned).length;
|
|
294
|
+
|
|
295
|
+
let overallProgress = 0;
|
|
296
|
+
if (validCourses.length > 0) {
|
|
297
|
+
const totalProgress = validCourses.reduce((sum, c) => sum + c.progressPercentage, 0);
|
|
298
|
+
overallProgress = Math.round(totalProgress / validCourses.length);
|
|
485
299
|
}
|
|
486
300
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
301
|
+
const coursesWithQuizzes = validCourses.filter((c) => c.quizScoreAverage !== undefined);
|
|
302
|
+
const avgQuizScore =
|
|
303
|
+
coursesWithQuizzes.length > 0 ? coursesWithQuizzes.reduce((sum, c) => sum + (c.quizScoreAverage || 0), 0) / coursesWithQuizzes.length : undefined;
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
userId,
|
|
307
|
+
userEmail: '',
|
|
308
|
+
totalCourses: validCourses.length,
|
|
309
|
+
coursesCompleted: completed,
|
|
310
|
+
coursesInProgress: inProgress,
|
|
311
|
+
coursesNotStarted: notStarted,
|
|
312
|
+
overallProgressPercentage: overallProgress,
|
|
313
|
+
totalTimeSpent: totalTime,
|
|
314
|
+
totalCertificatesEarned: totalCerts,
|
|
315
|
+
averageQuizScore: avgQuizScore,
|
|
316
|
+
courses: validCourses,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Map course progress data from API response
|
|
322
|
+
*/
|
|
323
|
+
private mapCourseProgress(data: LWApiCourseProgressResponse): CourseProgress {
|
|
324
|
+
const progressData: LWApiProgressData = {
|
|
325
|
+
percentage: data.progress?.percentage ?? data.percentage,
|
|
326
|
+
completed_units: data.progress?.completed_units ?? data.completed_units,
|
|
327
|
+
total_units: data.progress?.total_units ?? data.total_units,
|
|
328
|
+
time_spent: data.progress?.time_spent ?? data.time_spent,
|
|
329
|
+
};
|
|
330
|
+
const progress = this.calculateProgress(progressData);
|
|
331
|
+
const status = this.determineCourseStatus(data);
|
|
332
|
+
|
|
333
|
+
return {
|
|
334
|
+
courseId: data.course_id || data.course?.id || '',
|
|
335
|
+
courseTitle: data.course_title || data.course?.title || 'Unknown Course',
|
|
336
|
+
enrollmentId: data.enrollment_id || data.id || '',
|
|
337
|
+
enrolledAt: this.parseLearnWorldsDate(data.enrolled_at || data.created || ''),
|
|
338
|
+
lastAccessedAt: data.last_accessed_at ? this.parseLearnWorldsDate(data.last_accessed_at) : undefined,
|
|
339
|
+
|
|
340
|
+
progressPercentage: progress.percentage,
|
|
341
|
+
completedUnits: progress.completedUnits,
|
|
342
|
+
totalUnits: progress.totalUnits,
|
|
343
|
+
completedLessons: data.completed_lessons || 0,
|
|
344
|
+
totalLessons: data.total_lessons || 0,
|
|
345
|
+
|
|
346
|
+
totalTimeSpent: progress.timeSpent,
|
|
347
|
+
averageSessionTime: data.average_session_time || 0,
|
|
348
|
+
estimatedTimeToComplete: this.calculateEstimatedTimeToComplete(data),
|
|
349
|
+
|
|
350
|
+
quizScoreAverage: data.quiz_score_average,
|
|
351
|
+
assignmentsCompleted: data.assignments_completed,
|
|
352
|
+
assignmentsTotal: data.assignments_total,
|
|
353
|
+
currentGrade: data.current_grade || data.grade,
|
|
354
|
+
|
|
355
|
+
status,
|
|
356
|
+
completedAt: data.completed_at ? this.parseLearnWorldsDate(data.completed_at) : undefined,
|
|
357
|
+
expiresAt: data.expires_at ? this.parseLearnWorldsDate(data.expires_at) : undefined,
|
|
358
|
+
certificateEarned: data.certificate_earned || false,
|
|
359
|
+
certificateUrl: data.certificate_url,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Map unit progress data from API response
|
|
365
|
+
*/
|
|
366
|
+
private async mapUnitProgress(unitData: LWApiUnitData, includeLessons: boolean): Promise<UnitProgress> {
|
|
367
|
+
const unitProgress: UnitProgress = {
|
|
368
|
+
unitId: unitData.id || unitData.unit_id || '',
|
|
369
|
+
unitTitle: unitData.title || unitData.name || '',
|
|
370
|
+
unitType: (unitData.type as UnitProgress['unitType']) || 'section',
|
|
371
|
+
order: unitData.order || unitData.position || 0,
|
|
372
|
+
|
|
373
|
+
progressPercentage: unitData.progress_percentage || 0,
|
|
374
|
+
completedLessons: unitData.completed_lessons || 0,
|
|
375
|
+
totalLessons: unitData.total_lessons || 0,
|
|
376
|
+
timeSpent: unitData.time_spent || 0,
|
|
377
|
+
|
|
378
|
+
status: this.determineUnitStatus(unitData),
|
|
379
|
+
startedAt: unitData.started_at ? this.parseLearnWorldsDate(unitData.started_at) : undefined,
|
|
380
|
+
completedAt: unitData.completed_at ? this.parseLearnWorldsDate(unitData.completed_at) : undefined,
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
if (includeLessons && unitData.lessons) {
|
|
384
|
+
unitProgress.lessons = unitData.lessons.map((lesson) => this.mapLessonProgress(lesson));
|
|
503
385
|
}
|
|
504
386
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
387
|
+
return unitProgress;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Map lesson progress data from API response
|
|
392
|
+
*/
|
|
393
|
+
private mapLessonProgress(lessonData: LWApiLessonData): LessonProgress {
|
|
394
|
+
return {
|
|
395
|
+
lessonId: lessonData.id || lessonData.lesson_id || '',
|
|
396
|
+
lessonTitle: lessonData.title || lessonData.name || '',
|
|
397
|
+
lessonType: this.mapLessonType(lessonData.type || ''),
|
|
398
|
+
order: lessonData.order || lessonData.position || 0,
|
|
399
|
+
|
|
400
|
+
completed: lessonData.completed || false,
|
|
401
|
+
progressPercentage: lessonData.progress_percentage || (lessonData.completed ? 100 : 0),
|
|
402
|
+
timeSpent: lessonData.time_spent || 0,
|
|
403
|
+
|
|
404
|
+
startedAt: lessonData.started_at ? this.parseLearnWorldsDate(lessonData.started_at) : undefined,
|
|
405
|
+
completedAt: lessonData.completed_at ? this.parseLearnWorldsDate(lessonData.completed_at) : undefined,
|
|
406
|
+
lastAccessedAt: lessonData.last_accessed_at ? this.parseLearnWorldsDate(lessonData.last_accessed_at) : undefined,
|
|
407
|
+
|
|
408
|
+
videoWatchTime: lessonData.video_watch_time,
|
|
409
|
+
videoTotalTime: lessonData.video_total_time,
|
|
410
|
+
quizScore: lessonData.quiz_score,
|
|
411
|
+
quizMaxScore: lessonData.quiz_max_score,
|
|
412
|
+
quizAttempts: lessonData.quiz_attempts,
|
|
413
|
+
assignmentSubmitted: lessonData.assignment_submitted,
|
|
414
|
+
assignmentGrade: lessonData.assignment_grade,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Determine course status from data
|
|
420
|
+
*/
|
|
421
|
+
private determineCourseStatus(data: LWApiCourseProgressResponse): 'not_started' | 'in_progress' | 'completed' | 'expired' {
|
|
422
|
+
if (data.expired || (data.expires_at && new Date(data.expires_at as string | number) < new Date())) {
|
|
423
|
+
return 'expired';
|
|
521
424
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
425
|
+
if (data.completed || data.progress_percentage === 100) {
|
|
426
|
+
return 'completed';
|
|
427
|
+
}
|
|
428
|
+
if ((data.progress_percentage != null && data.progress_percentage > 0) || data.started) {
|
|
429
|
+
return 'in_progress';
|
|
430
|
+
}
|
|
431
|
+
return 'not_started';
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Determine unit status
|
|
436
|
+
*/
|
|
437
|
+
private determineUnitStatus(data: LWApiUnitData): 'not_started' | 'in_progress' | 'completed' {
|
|
438
|
+
if (data.completed || data.progress_percentage === 100) {
|
|
439
|
+
return 'completed';
|
|
440
|
+
}
|
|
441
|
+
if ((data.progress_percentage != null && data.progress_percentage > 0) || data.started) {
|
|
442
|
+
return 'in_progress';
|
|
443
|
+
}
|
|
444
|
+
return 'not_started';
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Map lesson type string to typed union
|
|
449
|
+
*/
|
|
450
|
+
private mapLessonType(type: string): LessonType {
|
|
451
|
+
const typeMap: Record<string, LessonType> = {
|
|
452
|
+
video: 'video',
|
|
453
|
+
text: 'text',
|
|
454
|
+
quiz: 'quiz',
|
|
455
|
+
exam: 'quiz',
|
|
456
|
+
assignment: 'assignment',
|
|
457
|
+
scorm: 'scorm',
|
|
458
|
+
interactive: 'interactive',
|
|
459
|
+
multimedia: 'interactive',
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
return typeMap[type?.toLowerCase()] || 'text';
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Calculate estimated time to complete
|
|
467
|
+
*/
|
|
468
|
+
private calculateEstimatedTimeToComplete(data: LWApiCourseProgressResponse): number | undefined {
|
|
469
|
+
if (data.estimated_time_to_complete) {
|
|
470
|
+
return data.estimated_time_to_complete;
|
|
543
471
|
}
|
|
544
472
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
const activeCourses = progress.courses.filter(c => c.status === 'in_progress');
|
|
550
|
-
const recentActivity = progress.courses
|
|
551
|
-
.filter(c => c.lastAccessedAt)
|
|
552
|
-
.sort((a, b) => (b.lastAccessedAt?.getTime() || 0) - (a.lastAccessedAt?.getTime() || 0))
|
|
553
|
-
.slice(0, 5);
|
|
554
|
-
|
|
555
|
-
return {
|
|
556
|
-
overview: {
|
|
557
|
-
totalCourses: progress.totalCourses,
|
|
558
|
-
completedCourses: progress.coursesCompleted,
|
|
559
|
-
inProgressCourses: progress.coursesInProgress,
|
|
560
|
-
notStartedCourses: progress.coursesNotStarted,
|
|
561
|
-
overallProgress: `${progress.overallProgressPercentage}%`,
|
|
562
|
-
certificatesEarned: progress.totalCertificatesEarned,
|
|
563
|
-
totalLearningTime: this.formatDuration(progress.totalTimeSpent)
|
|
564
|
-
},
|
|
565
|
-
performance: {
|
|
566
|
-
averageQuizScore: progress.averageQuizScore ? `${Math.round(progress.averageQuizScore)}%` : 'N/A',
|
|
567
|
-
averageCourseProgress: `${progress.overallProgressPercentage}%`,
|
|
568
|
-
completionRate: progress.totalCourses > 0 ?
|
|
569
|
-
`${Math.round((progress.coursesCompleted / progress.totalCourses) * 100)}%` : '0%'
|
|
570
|
-
},
|
|
571
|
-
currentFocus: activeCourses.map(c => ({
|
|
572
|
-
courseTitle: c.courseTitle,
|
|
573
|
-
progress: `${c.progressPercentage}%`,
|
|
574
|
-
timeSpent: this.formatDuration(c.totalTimeSpent),
|
|
575
|
-
estimatedTimeToComplete: c.estimatedTimeToComplete ?
|
|
576
|
-
this.formatDuration(c.estimatedTimeToComplete) : 'N/A'
|
|
577
|
-
})),
|
|
578
|
-
recentActivity: recentActivity.map(c => ({
|
|
579
|
-
courseTitle: c.courseTitle,
|
|
580
|
-
lastAccessed: c.lastAccessedAt,
|
|
581
|
-
progress: `${c.progressPercentage}%`
|
|
582
|
-
})),
|
|
583
|
-
achievements: {
|
|
584
|
-
totalCertificates: progress.totalCertificatesEarned,
|
|
585
|
-
coursesWithCertificates: progress.courses
|
|
586
|
-
.filter(c => c.certificateEarned)
|
|
587
|
-
.map(c => ({
|
|
588
|
-
courseTitle: c.courseTitle,
|
|
589
|
-
completedAt: c.completedAt
|
|
590
|
-
}))
|
|
591
|
-
}
|
|
592
|
-
};
|
|
473
|
+
if (data.total_time_spent && data.progress_percentage != null && data.progress_percentage > 0 && data.progress_percentage < 100) {
|
|
474
|
+
const timePerPercent = data.total_time_spent / data.progress_percentage;
|
|
475
|
+
const remainingPercent = 100 - data.progress_percentage;
|
|
476
|
+
return Math.round(timePerPercent * remainingPercent);
|
|
593
477
|
}
|
|
594
478
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
},
|
|
612
|
-
{
|
|
613
|
-
Name: 'IncludeUnitDetails',
|
|
614
|
-
Type: 'Input',
|
|
615
|
-
Value: false
|
|
616
|
-
},
|
|
617
|
-
{
|
|
618
|
-
Name: 'IncludeLessonDetails',
|
|
619
|
-
Type: 'Input',
|
|
620
|
-
Value: false
|
|
621
|
-
}
|
|
622
|
-
];
|
|
623
|
-
|
|
624
|
-
return [...baseParams, ...specificParams];
|
|
479
|
+
return undefined;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Calculate learning analytics
|
|
484
|
+
*/
|
|
485
|
+
private calculateLearningAnalytics(progress: UserLearningProgress): void {
|
|
486
|
+
if (progress.courses.length === 0) return;
|
|
487
|
+
|
|
488
|
+
const lastDates = progress.courses.map((c) => c.lastAccessedAt).filter((d): d is Date => d !== undefined);
|
|
489
|
+
|
|
490
|
+
if (lastDates.length > 0) {
|
|
491
|
+
progress.lastLearningDate = new Date(Math.max(...lastDates.map((d) => d.getTime())));
|
|
492
|
+
|
|
493
|
+
const daysSinceLastActivity = Math.floor((new Date().getTime() - progress.lastLearningDate.getTime()) / (1000 * 60 * 60 * 24));
|
|
494
|
+
progress.learningStreak = daysSinceLastActivity <= 1 ? 1 : 0;
|
|
625
495
|
}
|
|
626
|
-
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Create progress summary
|
|
500
|
+
*/
|
|
501
|
+
private createProgressSummary(progress: UserLearningProgress): Record<string, unknown> {
|
|
502
|
+
const activeCourses = progress.courses.filter((c) => c.status === 'in_progress');
|
|
503
|
+
const recentActivity = progress.courses
|
|
504
|
+
.filter((c) => c.lastAccessedAt)
|
|
505
|
+
.sort((a, b) => (b.lastAccessedAt?.getTime() || 0) - (a.lastAccessedAt?.getTime() || 0))
|
|
506
|
+
.slice(0, 5);
|
|
507
|
+
|
|
508
|
+
return {
|
|
509
|
+
overview: {
|
|
510
|
+
totalCourses: progress.totalCourses,
|
|
511
|
+
completedCourses: progress.coursesCompleted,
|
|
512
|
+
inProgressCourses: progress.coursesInProgress,
|
|
513
|
+
notStartedCourses: progress.coursesNotStarted,
|
|
514
|
+
overallProgress: `${progress.overallProgressPercentage}%`,
|
|
515
|
+
certificatesEarned: progress.totalCertificatesEarned,
|
|
516
|
+
totalLearningTime: this.formatDuration(progress.totalTimeSpent),
|
|
517
|
+
},
|
|
518
|
+
performance: {
|
|
519
|
+
averageQuizScore: progress.averageQuizScore ? `${Math.round(progress.averageQuizScore)}%` : 'N/A',
|
|
520
|
+
averageCourseProgress: `${progress.overallProgressPercentage}%`,
|
|
521
|
+
completionRate: progress.totalCourses > 0 ? `${Math.round((progress.coursesCompleted / progress.totalCourses) * 100)}%` : '0%',
|
|
522
|
+
},
|
|
523
|
+
currentFocus: activeCourses.map((c) => ({
|
|
524
|
+
courseTitle: c.courseTitle,
|
|
525
|
+
progress: `${c.progressPercentage}%`,
|
|
526
|
+
timeSpent: this.formatDuration(c.totalTimeSpent),
|
|
527
|
+
estimatedTimeToComplete: c.estimatedTimeToComplete ? this.formatDuration(c.estimatedTimeToComplete) : 'N/A',
|
|
528
|
+
})),
|
|
529
|
+
recentActivity: recentActivity.map((c) => ({
|
|
530
|
+
courseTitle: c.courseTitle,
|
|
531
|
+
lastAccessed: c.lastAccessedAt,
|
|
532
|
+
progress: `${c.progressPercentage}%`,
|
|
533
|
+
})),
|
|
534
|
+
achievements: {
|
|
535
|
+
totalCertificates: progress.totalCertificatesEarned,
|
|
536
|
+
coursesWithCertificates: progress.courses
|
|
537
|
+
.filter((c) => c.certificateEarned)
|
|
538
|
+
.map((c) => ({
|
|
539
|
+
courseTitle: c.courseTitle,
|
|
540
|
+
completedAt: c.completedAt,
|
|
541
|
+
})),
|
|
542
|
+
},
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Define the parameters for this action
|
|
548
|
+
*/
|
|
549
|
+
public get Params(): ActionParam[] {
|
|
550
|
+
const baseParams = this.getCommonLMSParams();
|
|
551
|
+
|
|
552
|
+
const specificParams: ActionParam[] = [
|
|
553
|
+
{
|
|
554
|
+
Name: 'UserID',
|
|
555
|
+
Type: 'Input',
|
|
556
|
+
Value: null,
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
Name: 'CourseID',
|
|
560
|
+
Type: 'Input',
|
|
561
|
+
Value: null,
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
Name: 'IncludeUnitDetails',
|
|
565
|
+
Type: 'Input',
|
|
566
|
+
Value: false,
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
Name: 'IncludeLessonDetails',
|
|
570
|
+
Type: 'Input',
|
|
571
|
+
Value: false,
|
|
572
|
+
},
|
|
573
|
+
];
|
|
574
|
+
|
|
575
|
+
return [...baseParams, ...specificParams];
|
|
576
|
+
}
|
|
577
|
+
}
|