@memberjunction/actions-bizapps-lms 2.55.0 → 2.56.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 +15 -0
- package/README.md +321 -0
- package/dist/providers/learnworlds/actions/create-user.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/create-user.action.js +243 -0
- package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.js +208 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.js +301 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts +36 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js +333 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts +28 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.js +237 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts +28 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js +368 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js +228 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/index.d.ts +8 -0
- package/dist/providers/learnworlds/actions/index.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/index.js +8 -0
- package/dist/providers/learnworlds/actions/index.js.map +1 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.js +254 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.js.map +1 -0
- package/package.json +6 -6
- package/src/providers/learnworlds/actions/create-user.action.ts +249 -0
- package/src/providers/learnworlds/actions/enroll-user.action.ts +233 -0
- package/src/providers/learnworlds/actions/get-certificates.action.ts +332 -0
- package/src/providers/learnworlds/actions/get-course-analytics.action.ts +359 -0
- package/src/providers/learnworlds/actions/get-course-details.action.ts +267 -0
- package/src/providers/learnworlds/actions/get-quiz-results.action.ts +399 -0
- package/src/providers/learnworlds/actions/get-user-enrollments.action.ts +242 -0
- package/src/providers/learnworlds/actions/index.ts +9 -1
- package/src/providers/learnworlds/actions/update-user-progress.action.ts +277 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
2
|
+
import { LearnWorldsBaseAction } from '../learnworlds-base.action';
|
|
3
|
+
import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Action to update a user's course progress in LearnWorlds
|
|
7
|
+
*/
|
|
8
|
+
@RegisterClass(LearnWorldsBaseAction, 'UpdateUserProgressAction')
|
|
9
|
+
export class UpdateUserProgressAction extends LearnWorldsBaseAction {
|
|
10
|
+
/**
|
|
11
|
+
* Update user progress for a course or lesson
|
|
12
|
+
*/
|
|
13
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
14
|
+
const { Params, ContextUser } = params;
|
|
15
|
+
this.params = Params; // Set params for base class to use
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Extract and validate parameters
|
|
19
|
+
const userId = this.getParamValue(Params, 'UserID');
|
|
20
|
+
const courseId = this.getParamValue(Params, 'CourseID');
|
|
21
|
+
const lessonId = this.getParamValue(Params, 'LessonID');
|
|
22
|
+
const progressPercentage = this.getParamValue(Params, 'ProgressPercentage');
|
|
23
|
+
const completed = this.getParamValue(Params, 'Completed');
|
|
24
|
+
const timeSpent = this.getParamValue(Params, 'TimeSpent');
|
|
25
|
+
const score = this.getParamValue(Params, 'Score');
|
|
26
|
+
const notes = this.getParamValue(Params, 'Notes');
|
|
27
|
+
|
|
28
|
+
if (!userId) {
|
|
29
|
+
return {
|
|
30
|
+
Success: false,
|
|
31
|
+
ResultCode: 'VALIDATION_ERROR',
|
|
32
|
+
Message: 'UserID is required',
|
|
33
|
+
Params
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!courseId) {
|
|
38
|
+
return {
|
|
39
|
+
Success: false,
|
|
40
|
+
ResultCode: 'VALIDATION_ERROR',
|
|
41
|
+
Message: 'CourseID is required',
|
|
42
|
+
Params
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Get current enrollment first
|
|
47
|
+
let currentEnrollment: any;
|
|
48
|
+
try {
|
|
49
|
+
currentEnrollment = await this.makeLearnWorldsRequest<any>(
|
|
50
|
+
`users/${userId}/enrollments/${courseId}`,
|
|
51
|
+
'GET',
|
|
52
|
+
undefined,
|
|
53
|
+
ContextUser
|
|
54
|
+
);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return {
|
|
57
|
+
Success: false,
|
|
58
|
+
ResultCode: 'NOT_ENROLLED',
|
|
59
|
+
Message: 'User is not enrolled in this course',
|
|
60
|
+
Params
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
let updateResult: any = {};
|
|
64
|
+
|
|
65
|
+
// Update lesson progress if lessonId is provided
|
|
66
|
+
if (lessonId) {
|
|
67
|
+
const lessonProgressData: any = {
|
|
68
|
+
completed: completed !== undefined ? completed : false,
|
|
69
|
+
progress_percentage: progressPercentage
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
if (timeSpent !== undefined) {
|
|
73
|
+
lessonProgressData.time_spent = timeSpent;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (score !== undefined) {
|
|
77
|
+
lessonProgressData.score = score;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (notes) {
|
|
81
|
+
lessonProgressData.notes = notes;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const lessonUpdateData = await this.makeLearnWorldsRequest<any>(
|
|
86
|
+
`users/${userId}/courses/${courseId}/lessons/${lessonId}/progress`,
|
|
87
|
+
'PUT',
|
|
88
|
+
lessonProgressData,
|
|
89
|
+
ContextUser
|
|
90
|
+
);
|
|
91
|
+
updateResult.lessonProgress = lessonUpdateData;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
return {
|
|
94
|
+
Success: false,
|
|
95
|
+
ResultCode: 'UPDATE_FAILED',
|
|
96
|
+
Message: error instanceof Error ? error.message : 'Failed to update lesson progress',
|
|
97
|
+
Params
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Update overall course progress if progressPercentage is provided at course level
|
|
103
|
+
if (progressPercentage !== undefined && !lessonId) {
|
|
104
|
+
const courseProgressData: any = {
|
|
105
|
+
progress_percentage: progressPercentage
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
if (completed !== undefined) {
|
|
109
|
+
courseProgressData.completed = completed;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (timeSpent !== undefined) {
|
|
113
|
+
courseProgressData.total_time_spent = (currentEnrollment.total_time_spent || 0) + timeSpent;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
const courseUpdateData = await this.makeLearnWorldsRequest<any>(
|
|
118
|
+
`users/${userId}/enrollments/${courseId}/progress`,
|
|
119
|
+
'PUT',
|
|
120
|
+
courseProgressData,
|
|
121
|
+
ContextUser
|
|
122
|
+
);
|
|
123
|
+
updateResult.courseProgress = courseUpdateData;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
return {
|
|
126
|
+
Success: false,
|
|
127
|
+
ResultCode: 'UPDATE_FAILED',
|
|
128
|
+
Message: error instanceof Error ? error.message : 'Failed to update course progress',
|
|
129
|
+
Params
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Get updated enrollment details
|
|
135
|
+
let updatedProgress = currentEnrollment;
|
|
136
|
+
try {
|
|
137
|
+
updatedProgress = await this.makeLearnWorldsRequest<any>(
|
|
138
|
+
`users/${userId}/enrollments/${courseId}`,
|
|
139
|
+
'GET',
|
|
140
|
+
undefined,
|
|
141
|
+
ContextUser
|
|
142
|
+
);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
// If we can't get updated details, use current enrollment
|
|
145
|
+
console.warn('Failed to get updated enrollment details:', error);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Format progress details
|
|
149
|
+
const progressDetails = {
|
|
150
|
+
userId: userId,
|
|
151
|
+
courseId: courseId,
|
|
152
|
+
lessonId: lessonId,
|
|
153
|
+
previousProgress: {
|
|
154
|
+
percentage: currentEnrollment.progress_percentage || 0,
|
|
155
|
+
completedUnits: currentEnrollment.completed_units || 0,
|
|
156
|
+
totalTimeSpent: currentEnrollment.total_time_spent || 0
|
|
157
|
+
},
|
|
158
|
+
updatedProgress: {
|
|
159
|
+
percentage: updatedProgress.progress_percentage || 0,
|
|
160
|
+
completedUnits: updatedProgress.completed_units || 0,
|
|
161
|
+
totalUnits: updatedProgress.total_units || 0,
|
|
162
|
+
totalTimeSpent: updatedProgress.total_time_spent || 0,
|
|
163
|
+
totalTimeSpentText: this.formatDuration(updatedProgress.total_time_spent || 0),
|
|
164
|
+
lastAccessedAt: updatedProgress.last_accessed_at || new Date().toISOString(),
|
|
165
|
+
completed: updatedProgress.completed || false,
|
|
166
|
+
completedAt: updatedProgress.completed_at
|
|
167
|
+
},
|
|
168
|
+
updateType: lessonId ? 'lesson' : 'course',
|
|
169
|
+
updateResult: updateResult
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// Create summary
|
|
173
|
+
const summary = {
|
|
174
|
+
userId: userId,
|
|
175
|
+
courseId: courseId,
|
|
176
|
+
lessonId: lessonId,
|
|
177
|
+
progressIncreased: (updatedProgress.progress_percentage || 0) > (currentEnrollment.progress_percentage || 0),
|
|
178
|
+
previousPercentage: currentEnrollment.progress_percentage || 0,
|
|
179
|
+
newPercentage: updatedProgress.progress_percentage || 0,
|
|
180
|
+
timeAdded: timeSpent || 0,
|
|
181
|
+
totalTimeSpent: updatedProgress.total_time_spent || 0,
|
|
182
|
+
isCompleted: updatedProgress.completed || false,
|
|
183
|
+
updateType: progressDetails.updateType
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Update output parameters
|
|
187
|
+
const outputParams = [...Params];
|
|
188
|
+
const progressDetailsParam = outputParams.find(p => p.Name === 'ProgressDetails');
|
|
189
|
+
if (progressDetailsParam) progressDetailsParam.Value = progressDetails;
|
|
190
|
+
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
191
|
+
if (summaryParam) summaryParam.Value = summary;
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
Success: true,
|
|
195
|
+
ResultCode: 'SUCCESS',
|
|
196
|
+
Message: `Successfully updated ${progressDetails.updateType} progress`,
|
|
197
|
+
Params: outputParams
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
} catch (error) {
|
|
201
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
202
|
+
return {
|
|
203
|
+
Success: false,
|
|
204
|
+
ResultCode: 'ERROR',
|
|
205
|
+
Message: `Error updating progress: ${errorMessage}`,
|
|
206
|
+
Params
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Define the parameters this action expects
|
|
213
|
+
*/
|
|
214
|
+
public get Params(): ActionParam[] {
|
|
215
|
+
const baseParams = this.getCommonLMSParams();
|
|
216
|
+
const specificParams: ActionParam[] = [
|
|
217
|
+
{
|
|
218
|
+
Name: 'UserID',
|
|
219
|
+
Type: 'Input',
|
|
220
|
+
Value: null
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
Name: 'CourseID',
|
|
224
|
+
Type: 'Input',
|
|
225
|
+
Value: null
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
Name: 'LessonID',
|
|
229
|
+
Type: 'Input',
|
|
230
|
+
Value: null
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
Name: 'ProgressPercentage',
|
|
234
|
+
Type: 'Input',
|
|
235
|
+
Value: null
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
Name: 'Completed',
|
|
239
|
+
Type: 'Input',
|
|
240
|
+
Value: null
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
Name: 'TimeSpent',
|
|
244
|
+
Type: 'Input',
|
|
245
|
+
Value: null
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
Name: 'Score',
|
|
249
|
+
Type: 'Input',
|
|
250
|
+
Value: null
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
Name: 'Notes',
|
|
254
|
+
Type: 'Input',
|
|
255
|
+
Value: null
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
Name: 'ProgressDetails',
|
|
259
|
+
Type: 'Output',
|
|
260
|
+
Value: null
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
Name: 'Summary',
|
|
264
|
+
Type: 'Output',
|
|
265
|
+
Value: null
|
|
266
|
+
}
|
|
267
|
+
];
|
|
268
|
+
return [...baseParams, ...specificParams];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Metadata about this action
|
|
273
|
+
*/
|
|
274
|
+
public get Description(): string {
|
|
275
|
+
return 'Updates a user\'s progress for a course or specific lesson in LearnWorlds';
|
|
276
|
+
}
|
|
277
|
+
}
|