@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,233 @@
|
|
|
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 enroll a user in a LearnWorlds course
|
|
7
|
+
*/
|
|
8
|
+
@RegisterClass(LearnWorldsBaseAction, 'EnrollUserAction')
|
|
9
|
+
export class EnrollUserAction extends LearnWorldsBaseAction {
|
|
10
|
+
/**
|
|
11
|
+
* Enroll a user in a course
|
|
12
|
+
*/
|
|
13
|
+
public async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
14
|
+
const { Params, ContextUser } = params;
|
|
15
|
+
this.params = Params;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Extract and validate parameters
|
|
19
|
+
const userId = this.getParamValue(Params, 'UserID');
|
|
20
|
+
const courseId = this.getParamValue(Params, 'CourseID');
|
|
21
|
+
const price = this.getParamValue(Params, 'Price') || 0;
|
|
22
|
+
const justification = this.getParamValue(Params, 'Justification') || 'API Enrollment';
|
|
23
|
+
const notifyUser = this.getParamValue(Params, 'NotifyUser') !== false;
|
|
24
|
+
const startDate = this.getParamValue(Params, 'StartDate');
|
|
25
|
+
const expiryDate = this.getParamValue(Params, 'ExpiryDate');
|
|
26
|
+
|
|
27
|
+
if (!userId) {
|
|
28
|
+
return {
|
|
29
|
+
Success: false,
|
|
30
|
+
ResultCode: 'VALIDATION_ERROR',
|
|
31
|
+
Message: 'UserID is required',
|
|
32
|
+
Params
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!courseId) {
|
|
37
|
+
return {
|
|
38
|
+
Success: false,
|
|
39
|
+
ResultCode: 'VALIDATION_ERROR',
|
|
40
|
+
Message: 'CourseID is required',
|
|
41
|
+
Params
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
// Prepare enrollment data
|
|
47
|
+
const enrollmentData: any = {
|
|
48
|
+
user_id: userId,
|
|
49
|
+
justification: justification,
|
|
50
|
+
price: price,
|
|
51
|
+
notify_user: notifyUser
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (startDate) {
|
|
55
|
+
enrollmentData.starts_at = new Date(startDate).toISOString();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (expiryDate) {
|
|
59
|
+
enrollmentData.expires_at = new Date(expiryDate).toISOString();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Create enrollment
|
|
63
|
+
const enrollmentResponse = await this.makeLearnWorldsRequest(
|
|
64
|
+
`/courses/${courseId}/enrollments`,
|
|
65
|
+
'POST',
|
|
66
|
+
enrollmentData,
|
|
67
|
+
ContextUser
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
if (!enrollmentResponse.success) {
|
|
71
|
+
return {
|
|
72
|
+
Success: false,
|
|
73
|
+
ResultCode: 'API_ERROR',
|
|
74
|
+
Message: enrollmentResponse.message || 'Failed to enroll user',
|
|
75
|
+
Params
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const enrollment = enrollmentResponse.data;
|
|
80
|
+
|
|
81
|
+
// Format enrollment details
|
|
82
|
+
const enrollmentDetails = {
|
|
83
|
+
id: enrollment.id,
|
|
84
|
+
userId: enrollment.user_id || userId,
|
|
85
|
+
courseId: enrollment.course_id || courseId,
|
|
86
|
+
enrolledAt: enrollment.enrolled_at || enrollment.created_at,
|
|
87
|
+
startsAt: enrollment.starts_at,
|
|
88
|
+
expiresAt: enrollment.expires_at,
|
|
89
|
+
status: enrollment.status || 'active',
|
|
90
|
+
price: enrollment.price || price,
|
|
91
|
+
progress: {
|
|
92
|
+
percentage: enrollment.progress_percentage || 0,
|
|
93
|
+
completedUnits: enrollment.completed_units || 0,
|
|
94
|
+
totalUnits: enrollment.total_units || 0,
|
|
95
|
+
lastAccessedAt: enrollment.last_accessed_at
|
|
96
|
+
},
|
|
97
|
+
certificateEligible: enrollment.certificate_eligible || false,
|
|
98
|
+
certificateIssuedAt: enrollment.certificate_issued_at
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// Get course and user details for summary
|
|
102
|
+
let courseTitle = 'Unknown Course';
|
|
103
|
+
let userName = 'Unknown User';
|
|
104
|
+
|
|
105
|
+
// Try to get course details
|
|
106
|
+
const courseResponse = await this.makeLearnWorldsRequest(
|
|
107
|
+
`/courses/${courseId}`,
|
|
108
|
+
'GET',
|
|
109
|
+
null,
|
|
110
|
+
ContextUser
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
if (courseResponse.success && courseResponse.data) {
|
|
114
|
+
courseTitle = courseResponse.data.title || courseTitle;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Try to get user details
|
|
118
|
+
const userResponse = await this.makeLearnWorldsRequest(
|
|
119
|
+
`/users/${userId}`,
|
|
120
|
+
'GET',
|
|
121
|
+
null,
|
|
122
|
+
ContextUser
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
if (userResponse.success && userResponse.data) {
|
|
126
|
+
const user = userResponse.data;
|
|
127
|
+
userName = user.email || user.username || userName;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Create summary
|
|
131
|
+
const summary = {
|
|
132
|
+
enrollmentId: enrollmentDetails.id,
|
|
133
|
+
userId: userId,
|
|
134
|
+
userName: userName,
|
|
135
|
+
courseId: courseId,
|
|
136
|
+
courseTitle: courseTitle,
|
|
137
|
+
enrolledAt: enrollmentDetails.enrolledAt,
|
|
138
|
+
status: enrollmentDetails.status,
|
|
139
|
+
price: enrollmentDetails.price,
|
|
140
|
+
notificationSent: notifyUser
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// Update output parameters
|
|
144
|
+
const outputParams = [...Params];
|
|
145
|
+
const enrollmentDetailsParam = outputParams.find(p => p.Name === 'EnrollmentDetails');
|
|
146
|
+
if (enrollmentDetailsParam) {
|
|
147
|
+
enrollmentDetailsParam.Value = enrollmentDetails;
|
|
148
|
+
}
|
|
149
|
+
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
150
|
+
if (summaryParam) {
|
|
151
|
+
summaryParam.Value = summary;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
Success: true,
|
|
156
|
+
ResultCode: 'SUCCESS',
|
|
157
|
+
Message: `Successfully enrolled user ${userName} in course ${courseTitle}`,
|
|
158
|
+
Params: outputParams
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
} catch (error) {
|
|
162
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
163
|
+
return {
|
|
164
|
+
Success: false,
|
|
165
|
+
ResultCode: 'EXECUTION_ERROR',
|
|
166
|
+
Message: `Error enrolling user: ${errorMessage}`,
|
|
167
|
+
Params
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Define the parameters this action expects
|
|
174
|
+
*/
|
|
175
|
+
public get Params(): ActionParam[] {
|
|
176
|
+
const baseParams = this.getCommonLMSParams();
|
|
177
|
+
const specificParams: ActionParam[] = [
|
|
178
|
+
{
|
|
179
|
+
Name: 'UserID',
|
|
180
|
+
Type: 'Input',
|
|
181
|
+
Value: null
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
Name: 'CourseID',
|
|
185
|
+
Type: 'Input',
|
|
186
|
+
Value: null
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
Name: 'Price',
|
|
190
|
+
Type: 'Input',
|
|
191
|
+
Value: 0
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
Name: 'Justification',
|
|
195
|
+
Type: 'Input',
|
|
196
|
+
Value: 'API Enrollment'
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
Name: 'NotifyUser',
|
|
200
|
+
Type: 'Input',
|
|
201
|
+
Value: true
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
Name: 'StartDate',
|
|
205
|
+
Type: 'Input',
|
|
206
|
+
Value: null
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
Name: 'ExpiryDate',
|
|
210
|
+
Type: 'Input',
|
|
211
|
+
Value: null
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
Name: 'EnrollmentDetails',
|
|
215
|
+
Type: 'Output',
|
|
216
|
+
Value: null
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
Name: 'Summary',
|
|
220
|
+
Type: 'Output',
|
|
221
|
+
Value: null
|
|
222
|
+
}
|
|
223
|
+
];
|
|
224
|
+
return [...baseParams, ...specificParams];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Metadata about this action
|
|
229
|
+
*/
|
|
230
|
+
public get Description(): string {
|
|
231
|
+
return 'Enrolls a user in a LearnWorlds course with optional pricing and notification settings';
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
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 retrieve certificates earned by users in LearnWorlds
|
|
7
|
+
*/
|
|
8
|
+
@RegisterClass(LearnWorldsBaseAction, 'GetCertificatesAction')
|
|
9
|
+
export class GetCertificatesAction extends LearnWorldsBaseAction {
|
|
10
|
+
/**
|
|
11
|
+
* Get certificates for a user or course
|
|
12
|
+
*/
|
|
13
|
+
public async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
14
|
+
const { Params, ContextUser } = params;
|
|
15
|
+
this.params = Params;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Extract and validate parameters
|
|
19
|
+
const userId = this.getParamValue(Params, 'UserID');
|
|
20
|
+
const courseId = this.getParamValue(Params, 'CourseID');
|
|
21
|
+
const dateFrom = this.getParamValue(Params, 'DateFrom');
|
|
22
|
+
const dateTo = this.getParamValue(Params, 'DateTo');
|
|
23
|
+
const includeDownloadLinks = this.getParamValue(Params, 'IncludeDownloadLinks') !== false;
|
|
24
|
+
const sortBy = this.getParamValue(Params, 'SortBy') || 'issued_at';
|
|
25
|
+
const sortOrder = this.getParamValue(Params, 'SortOrder') || 'desc';
|
|
26
|
+
const maxResults = this.getParamValue(Params, 'MaxResults') || 100;
|
|
27
|
+
|
|
28
|
+
// Require either userId or courseId
|
|
29
|
+
if (!userId && !courseId) {
|
|
30
|
+
return {
|
|
31
|
+
Success: false,
|
|
32
|
+
ResultCode: 'VALIDATION_ERROR',
|
|
33
|
+
Message: 'Either UserID or CourseID is required',
|
|
34
|
+
Params
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// Build query parameters
|
|
40
|
+
const queryParams: any = {
|
|
41
|
+
limit: Math.min(maxResults, 100),
|
|
42
|
+
sort: sortBy,
|
|
43
|
+
order: sortOrder
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (dateFrom) {
|
|
47
|
+
queryParams.issued_after = new Date(dateFrom).toISOString();
|
|
48
|
+
}
|
|
49
|
+
if (dateTo) {
|
|
50
|
+
queryParams.issued_before = new Date(dateTo).toISOString();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Determine endpoint based on parameters
|
|
54
|
+
let endpoint = '/certificates';
|
|
55
|
+
if (userId && courseId) {
|
|
56
|
+
// Get specific certificate for user/course combination
|
|
57
|
+
endpoint = `/users/${userId}/courses/${courseId}/certificate`;
|
|
58
|
+
} else if (userId) {
|
|
59
|
+
// Get all certificates for a user
|
|
60
|
+
endpoint = `/users/${userId}/certificates`;
|
|
61
|
+
} else if (courseId) {
|
|
62
|
+
// Get all certificates issued for a course
|
|
63
|
+
endpoint = `/courses/${courseId}/certificates`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Build query string
|
|
67
|
+
const queryString = Object.keys(queryParams).length > 0
|
|
68
|
+
? '?' + new URLSearchParams(queryParams).toString()
|
|
69
|
+
: '';
|
|
70
|
+
|
|
71
|
+
// Get certificates
|
|
72
|
+
const certificatesResponse = await this.makeLearnWorldsRequest(
|
|
73
|
+
endpoint + queryString,
|
|
74
|
+
'GET',
|
|
75
|
+
null,
|
|
76
|
+
ContextUser
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (!certificatesResponse.success) {
|
|
80
|
+
return {
|
|
81
|
+
Success: false,
|
|
82
|
+
ResultCode: 'API_ERROR',
|
|
83
|
+
Message: certificatesResponse.message || 'Failed to retrieve certificates',
|
|
84
|
+
Params
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Handle single certificate vs array
|
|
89
|
+
const rawData = certificatesResponse.data;
|
|
90
|
+
const certificatesArray = Array.isArray(rawData)
|
|
91
|
+
? rawData
|
|
92
|
+
: (rawData?.data || (rawData?.id ? [rawData] : []));
|
|
93
|
+
|
|
94
|
+
const formattedCertificates: any[] = [];
|
|
95
|
+
|
|
96
|
+
// Process each certificate
|
|
97
|
+
for (const cert of certificatesArray) {
|
|
98
|
+
const formattedCert: any = {
|
|
99
|
+
id: cert.id || cert.certificate_id,
|
|
100
|
+
userId: cert.user_id || userId,
|
|
101
|
+
courseId: cert.course_id || courseId,
|
|
102
|
+
certificateNumber: cert.certificate_number || cert.number,
|
|
103
|
+
issuedAt: cert.issued_at || cert.created_at,
|
|
104
|
+
expiresAt: cert.expires_at,
|
|
105
|
+
status: cert.status || 'active',
|
|
106
|
+
grade: cert.grade,
|
|
107
|
+
score: cert.score,
|
|
108
|
+
completionPercentage: cert.completion_percentage || 100
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Add user info if available
|
|
112
|
+
if (cert.user) {
|
|
113
|
+
formattedCert.user = {
|
|
114
|
+
id: cert.user.id || cert.user_id,
|
|
115
|
+
email: cert.user.email,
|
|
116
|
+
name: cert.user.name || `${cert.user.first_name || ''} ${cert.user.last_name || ''}`.trim()
|
|
117
|
+
};
|
|
118
|
+
} else if (!userId && cert.user_id) {
|
|
119
|
+
// Try to get user info
|
|
120
|
+
const userResponse = await this.makeLearnWorldsRequest(
|
|
121
|
+
`/users/${cert.user_id}`,
|
|
122
|
+
'GET',
|
|
123
|
+
null,
|
|
124
|
+
ContextUser
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if (userResponse.success && userResponse.data) {
|
|
128
|
+
const user = userResponse.data;
|
|
129
|
+
formattedCert.user = {
|
|
130
|
+
id: user.id,
|
|
131
|
+
email: user.email,
|
|
132
|
+
name: `${user.first_name || ''} ${user.last_name || ''}`.trim() || user.username
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Add course info if available
|
|
138
|
+
if (cert.course) {
|
|
139
|
+
formattedCert.course = {
|
|
140
|
+
id: cert.course.id || cert.course_id,
|
|
141
|
+
title: cert.course.title,
|
|
142
|
+
duration: cert.course.duration
|
|
143
|
+
};
|
|
144
|
+
} else if (!courseId && cert.course_id) {
|
|
145
|
+
// Try to get course info
|
|
146
|
+
const courseResponse = await this.makeLearnWorldsRequest(
|
|
147
|
+
`/courses/${cert.course_id}`,
|
|
148
|
+
'GET',
|
|
149
|
+
null,
|
|
150
|
+
ContextUser
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
if (courseResponse.success && courseResponse.data) {
|
|
154
|
+
const course = courseResponse.data;
|
|
155
|
+
formattedCert.course = {
|
|
156
|
+
id: course.id,
|
|
157
|
+
title: course.title,
|
|
158
|
+
duration: course.duration
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Add download links if requested
|
|
164
|
+
if (includeDownloadLinks) {
|
|
165
|
+
formattedCert.downloadLinks = {
|
|
166
|
+
pdf: cert.pdf_url || cert.download_url,
|
|
167
|
+
image: cert.image_url,
|
|
168
|
+
publicUrl: cert.public_url || cert.certificate_url
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Add verification info
|
|
173
|
+
formattedCert.verification = {
|
|
174
|
+
url: cert.verification_url,
|
|
175
|
+
code: cert.verification_code,
|
|
176
|
+
qrCode: cert.qr_code_url
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
formattedCertificates.push(formattedCert);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Calculate summary statistics
|
|
183
|
+
const totalCertificates = formattedCertificates.length;
|
|
184
|
+
const activeCertificates = formattedCertificates.filter(c =>
|
|
185
|
+
c.status === 'active' && (!c.expiresAt || new Date(c.expiresAt) > new Date())
|
|
186
|
+
).length;
|
|
187
|
+
const expiredCertificates = formattedCertificates.filter(c =>
|
|
188
|
+
c.expiresAt && new Date(c.expiresAt) <= new Date()
|
|
189
|
+
).length;
|
|
190
|
+
|
|
191
|
+
// Group by course if getting user certificates
|
|
192
|
+
const certificatesByCourse: any = {};
|
|
193
|
+
if (userId && !courseId) {
|
|
194
|
+
formattedCertificates.forEach(cert => {
|
|
195
|
+
const courseTitle = cert.course?.title || 'Unknown Course';
|
|
196
|
+
if (!certificatesByCourse[courseTitle]) {
|
|
197
|
+
certificatesByCourse[courseTitle] = [];
|
|
198
|
+
}
|
|
199
|
+
certificatesByCourse[courseTitle].push(cert);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Group by user if getting course certificates
|
|
204
|
+
const certificatesByUser: any = {};
|
|
205
|
+
if (courseId && !userId) {
|
|
206
|
+
formattedCertificates.forEach(cert => {
|
|
207
|
+
const userName = cert.user?.name || cert.user?.email || 'Unknown User';
|
|
208
|
+
if (!certificatesByUser[userName]) {
|
|
209
|
+
certificatesByUser[userName] = [];
|
|
210
|
+
}
|
|
211
|
+
certificatesByUser[userName].push(cert);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Create summary
|
|
216
|
+
const summary = {
|
|
217
|
+
totalCertificates: totalCertificates,
|
|
218
|
+
activeCertificates: activeCertificates,
|
|
219
|
+
expiredCertificates: expiredCertificates,
|
|
220
|
+
dateRange: {
|
|
221
|
+
from: dateFrom || 'all-time',
|
|
222
|
+
to: dateTo || 'current'
|
|
223
|
+
},
|
|
224
|
+
filterType: userId && courseId ? 'user-course' : (userId ? 'user' : 'course'),
|
|
225
|
+
groupedData: userId && !courseId ? certificatesByCourse : (courseId && !userId ? certificatesByUser : null)
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// Update output parameters
|
|
229
|
+
const outputParams = [...Params];
|
|
230
|
+
const certificatesParam = outputParams.find(p => p.Name === 'Certificates');
|
|
231
|
+
if (certificatesParam) {
|
|
232
|
+
certificatesParam.Value = formattedCertificates;
|
|
233
|
+
}
|
|
234
|
+
const totalCountParam = outputParams.find(p => p.Name === 'TotalCount');
|
|
235
|
+
if (totalCountParam) {
|
|
236
|
+
totalCountParam.Value = totalCertificates;
|
|
237
|
+
}
|
|
238
|
+
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
239
|
+
if (summaryParam) {
|
|
240
|
+
summaryParam.Value = summary;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
Success: true,
|
|
245
|
+
ResultCode: 'SUCCESS',
|
|
246
|
+
Message: `Retrieved ${totalCertificates} certificate(s)`,
|
|
247
|
+
Params: outputParams
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
} catch (error) {
|
|
251
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
252
|
+
return {
|
|
253
|
+
Success: false,
|
|
254
|
+
ResultCode: 'EXECUTION_ERROR',
|
|
255
|
+
Message: `Error retrieving certificates: ${errorMessage}`,
|
|
256
|
+
Params
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Define the parameters this action expects
|
|
263
|
+
*/
|
|
264
|
+
public get Params(): ActionParam[] {
|
|
265
|
+
const baseParams = this.getCommonLMSParams();
|
|
266
|
+
const specificParams: ActionParam[] = [
|
|
267
|
+
{
|
|
268
|
+
Name: 'UserID',
|
|
269
|
+
Type: 'Input',
|
|
270
|
+
Value: null
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
Name: 'CourseID',
|
|
274
|
+
Type: 'Input',
|
|
275
|
+
Value: null
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
Name: 'DateFrom',
|
|
279
|
+
Type: 'Input',
|
|
280
|
+
Value: null
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
Name: 'DateTo',
|
|
284
|
+
Type: 'Input',
|
|
285
|
+
Value: null
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
Name: 'IncludeDownloadLinks',
|
|
289
|
+
Type: 'Input',
|
|
290
|
+
Value: true
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
Name: 'SortBy',
|
|
294
|
+
Type: 'Input',
|
|
295
|
+
Value: 'issued_at'
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
Name: 'SortOrder',
|
|
299
|
+
Type: 'Input',
|
|
300
|
+
Value: 'desc'
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
Name: 'MaxResults',
|
|
304
|
+
Type: 'Input',
|
|
305
|
+
Value: 100
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
Name: 'Certificates',
|
|
309
|
+
Type: 'Output',
|
|
310
|
+
Value: null
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
Name: 'TotalCount',
|
|
314
|
+
Type: 'Output',
|
|
315
|
+
Value: null
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
Name: 'Summary',
|
|
319
|
+
Type: 'Output',
|
|
320
|
+
Value: null
|
|
321
|
+
}
|
|
322
|
+
];
|
|
323
|
+
return [...baseParams, ...specificParams];
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Metadata about this action
|
|
328
|
+
*/
|
|
329
|
+
public get Description(): string {
|
|
330
|
+
return 'Retrieves certificates earned by users in LearnWorlds courses with download links and verification info';
|
|
331
|
+
}
|
|
332
|
+
}
|