@memberjunction/actions-bizapps-lms 5.3.0 → 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 +26 -0
- package/LEARNWORLDS_SIDECAR_PLAN.md +845 -0
- package/dist/base/base-lms.action.d.ts +26 -4
- package/dist/base/base-lms.action.d.ts.map +1 -1
- package/dist/base/base-lms.action.js +73 -17
- package/dist/base/base-lms.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/attach-tags.action.d.ts +26 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.js +79 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/create-user.action.d.ts +24 -1
- package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/create-user.action.js +166 -142
- package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/detach-tags.action.d.ts +26 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.js +79 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts +31 -3
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/enroll-user.action.js +179 -125
- package/dist/providers/learnworlds/actions/enroll-user.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts +79 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.js +359 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.d.ts +34 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.js +107 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts +33 -2
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-certificates.action.js +311 -244
- package/dist/providers/learnworlds/actions/get-certificates.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts +14 -14
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js +234 -226
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts +42 -6
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-details.action.js +182 -148
- package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts +29 -82
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-courses.action.js +188 -207
- package/dist/providers/learnworlds/actions/get-courses.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts +22 -2
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js +316 -294
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts +23 -59
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-details.action.js +113 -114
- package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts +43 -5
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js +191 -147
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts +21 -92
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-progress.action.js +145 -166
- package/dist/providers/learnworlds/actions/get-user-progress.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-users.action.d.ts +14 -28
- package/dist/providers/learnworlds/actions/get-users.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-users.action.js +122 -143
- package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/index.d.ts +7 -0
- package/dist/providers/learnworlds/actions/index.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/index.js +7 -0
- package/dist/providers/learnworlds/actions/index.js.map +1 -1
- package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts +53 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.js +236 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/sso-login.action.d.ts +35 -0
- package/dist/providers/learnworlds/actions/sso-login.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/sso-login.action.js +101 -0
- package/dist/providers/learnworlds/actions/sso-login.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts +12 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.js +167 -210
- package/dist/providers/learnworlds/actions/update-user-progress.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/update-user.action.d.ts +39 -0
- package/dist/providers/learnworlds/actions/update-user.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/update-user.action.js +168 -0
- package/dist/providers/learnworlds/actions/update-user.action.js.map +1 -0
- package/dist/providers/learnworlds/index.d.ts +1 -0
- package/dist/providers/learnworlds/index.d.ts.map +1 -1
- package/dist/providers/learnworlds/index.js +2 -0
- package/dist/providers/learnworlds/index.js.map +1 -1
- package/dist/providers/learnworlds/interfaces/bundle.types.d.ts +16 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.d.ts +66 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/common.types.d.ts +221 -0
- package/dist/providers/learnworlds/interfaces/common.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/common.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/common.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/course.types.d.ts +393 -0
- package/dist/providers/learnworlds/interfaces/course.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/course.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/course.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts +165 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/index.d.ts +12 -0
- package/dist/providers/learnworlds/interfaces/index.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/index.js +13 -0
- package/dist/providers/learnworlds/interfaces/index.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts +39 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.d.ts +108 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/sso.types.d.ts +18 -0
- package/dist/providers/learnworlds/interfaces/sso.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/sso.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/sso.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/sync.types.d.ts +44 -0
- package/dist/providers/learnworlds/interfaces/sync.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/sync.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/sync.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/tag.types.d.ts +17 -0
- package/dist/providers/learnworlds/interfaces/tag.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/tag.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/tag.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/user.types.d.ts +198 -0
- package/dist/providers/learnworlds/interfaces/user.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/user.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/user.types.js.map +1 -0
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts +111 -7
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/learnworlds-base.action.js +293 -56
- package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -1
- package/package.json +8 -7
- package/src/__tests__/attach-tags.action.test.ts +137 -0
- package/src/__tests__/create-user.action.test.ts +311 -0
- package/src/__tests__/detach-tags.action.test.ts +136 -0
- package/src/__tests__/enroll-user.action.test.ts +283 -0
- package/src/__tests__/get-bulk-data.action.test.ts +649 -0
- package/src/__tests__/get-bundles.action.test.ts +215 -0
- package/src/__tests__/lms.test.ts +275 -184
- package/src/__tests__/onboard-learner.action.test.ts +455 -0
- package/src/__tests__/sso-login.action.test.ts +256 -0
- package/src/__tests__/update-user.action.test.ts +350 -0
- package/src/base/base-lms.action.ts +226 -163
- package/src/providers/learnworlds/actions/attach-tags.action.ts +90 -0
- package/src/providers/learnworlds/actions/create-user.action.ts +291 -235
- package/src/providers/learnworlds/actions/detach-tags.action.ts +90 -0
- package/src/providers/learnworlds/actions/enroll-user.action.ts +326 -220
- package/src/providers/learnworlds/actions/get-bulk-data.action.ts +438 -0
- package/src/providers/learnworlds/actions/get-bundles.action.ts +139 -0
- package/src/providers/learnworlds/actions/get-certificates.action.ts +499 -309
- package/src/providers/learnworlds/actions/get-course-analytics.action.ts +470 -337
- package/src/providers/learnworlds/actions/get-course-details.action.ts +395 -249
- package/src/providers/learnworlds/actions/get-courses.action.ts +508 -565
- package/src/providers/learnworlds/actions/get-quiz-results.action.ts +606 -381
- package/src/providers/learnworlds/actions/get-user-details.action.ts +335 -349
- package/src/providers/learnworlds/actions/get-user-enrollments.action.ts +328 -228
- package/src/providers/learnworlds/actions/get-user-progress.action.ts +522 -571
- package/src/providers/learnworlds/actions/get-users.action.ts +231 -282
- package/src/providers/learnworlds/actions/index.ts +8 -1
- package/src/providers/learnworlds/actions/onboard-learner.action.ts +286 -0
- package/src/providers/learnworlds/actions/sso-login.action.ts +116 -0
- package/src/providers/learnworlds/actions/update-user-progress.action.ts +301 -263
- package/src/providers/learnworlds/actions/update-user.action.ts +181 -0
- package/src/providers/learnworlds/index.ts +4 -1
- package/src/providers/learnworlds/interfaces/bundle.types.ts +17 -0
- package/src/providers/learnworlds/interfaces/certificate.types.ts +69 -0
- package/src/providers/learnworlds/interfaces/common.types.ts +233 -0
- package/src/providers/learnworlds/interfaces/course.types.ts +411 -0
- package/src/providers/learnworlds/interfaces/enrollment.types.ts +176 -0
- package/src/providers/learnworlds/interfaces/index.ts +12 -0
- package/src/providers/learnworlds/interfaces/onboarding.types.ts +41 -0
- package/src/providers/learnworlds/interfaces/quiz.types.ts +118 -0
- package/src/providers/learnworlds/interfaces/sso.types.ts +19 -0
- package/src/providers/learnworlds/interfaces/sync.types.ts +46 -0
- package/src/providers/learnworlds/interfaces/tag.types.ts +18 -0
- package/src/providers/learnworlds/interfaces/user.types.ts +204 -0
- package/src/providers/learnworlds/learnworlds-base.action.ts +468 -210
- package/tsconfig.json +1 -1
- package/dist/__tests__/lms.test.d.ts +0 -2
- package/dist/__tests__/lms.test.d.ts.map +0 -1
- package/dist/__tests__/lms.test.js +0 -232
- package/dist/__tests__/lms.test.js.map +0 -1
|
@@ -2,399 +2,624 @@ 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
|
+
GetQuizResultsParams,
|
|
8
|
+
GetQuizResultsResult,
|
|
9
|
+
FormattedQuizResult,
|
|
10
|
+
FormattedQuestion,
|
|
11
|
+
FormattedAnswer,
|
|
12
|
+
QuizAnswerValue,
|
|
13
|
+
QuizMetrics,
|
|
14
|
+
QuizResultsSummary,
|
|
15
|
+
} from '../interfaces';
|
|
16
|
+
|
|
17
|
+
// ----------------------------------------------------------------
|
|
18
|
+
// File-local interfaces for raw LearnWorlds API shapes
|
|
19
|
+
// ----------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
/** Query parameters sent to quiz results endpoints */
|
|
22
|
+
interface LWQuizResultQueryParams {
|
|
23
|
+
limit: number;
|
|
24
|
+
sort: string;
|
|
25
|
+
order: string;
|
|
26
|
+
passed?: boolean;
|
|
27
|
+
completed_after?: string;
|
|
28
|
+
completed_before?: string;
|
|
29
|
+
user_id?: string;
|
|
30
|
+
[key: string]: string | number | boolean | undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Raw quiz result from the API */
|
|
34
|
+
interface LWRawQuizResult {
|
|
35
|
+
id?: string;
|
|
36
|
+
result_id?: string;
|
|
37
|
+
user_id?: string;
|
|
38
|
+
course_id?: string;
|
|
39
|
+
quiz_id?: string;
|
|
40
|
+
attempt_number?: number;
|
|
41
|
+
attempt?: number;
|
|
42
|
+
score?: number;
|
|
43
|
+
max_score?: number;
|
|
44
|
+
total_points?: number;
|
|
45
|
+
percentage?: number;
|
|
46
|
+
passed?: boolean;
|
|
47
|
+
is_passing?: boolean;
|
|
48
|
+
passing_score?: number;
|
|
49
|
+
passing_percentage?: number;
|
|
50
|
+
started_at?: string;
|
|
51
|
+
completed_at?: string;
|
|
52
|
+
submitted_at?: string;
|
|
53
|
+
duration?: number;
|
|
54
|
+
time_spent?: number;
|
|
55
|
+
user?: {
|
|
56
|
+
id?: string;
|
|
57
|
+
email?: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
first_name?: string;
|
|
60
|
+
last_name?: string;
|
|
61
|
+
};
|
|
62
|
+
quiz?: {
|
|
63
|
+
id?: string;
|
|
64
|
+
title?: string;
|
|
65
|
+
name?: string;
|
|
66
|
+
type?: string;
|
|
67
|
+
question_count?: number;
|
|
68
|
+
total_questions?: number;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Raw quiz detail response */
|
|
73
|
+
interface LWQuizDetailResponse {
|
|
74
|
+
success?: boolean;
|
|
75
|
+
data?: {
|
|
76
|
+
questions?: LWRawQuestion[];
|
|
77
|
+
answers?: LWRawAnswer[];
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Raw question from the API */
|
|
82
|
+
interface LWRawQuestion {
|
|
83
|
+
question_number?: number;
|
|
84
|
+
question_id?: string;
|
|
85
|
+
id?: string;
|
|
86
|
+
question_text?: string;
|
|
87
|
+
question?: string;
|
|
88
|
+
text?: string;
|
|
89
|
+
question_type?: string;
|
|
90
|
+
type?: string;
|
|
91
|
+
points?: number;
|
|
92
|
+
score?: number;
|
|
93
|
+
difficulty?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Raw answer from the API */
|
|
97
|
+
interface LWRawAnswer {
|
|
98
|
+
question_number?: number;
|
|
99
|
+
question_id?: string;
|
|
100
|
+
user_answer?: unknown;
|
|
101
|
+
answer?: unknown;
|
|
102
|
+
selected_answer?: unknown;
|
|
103
|
+
correct_answer?: unknown;
|
|
104
|
+
is_correct?: boolean;
|
|
105
|
+
correct?: boolean;
|
|
106
|
+
points_earned?: number;
|
|
107
|
+
points_possible?: number;
|
|
108
|
+
points?: number;
|
|
109
|
+
feedback?: string;
|
|
110
|
+
time_spent?: number;
|
|
111
|
+
answered_at?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Results API response wrapper */
|
|
115
|
+
interface LWQuizResultsApiResponse {
|
|
116
|
+
success?: boolean;
|
|
117
|
+
message?: string;
|
|
118
|
+
data?: LWRawQuizResult[] | { data?: LWRawQuizResult[] };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Quiz info lookup response */
|
|
122
|
+
interface LWQuizLookup {
|
|
123
|
+
success?: boolean;
|
|
124
|
+
data?: {
|
|
125
|
+
id?: string;
|
|
126
|
+
title?: string;
|
|
127
|
+
name?: string;
|
|
128
|
+
type?: string;
|
|
129
|
+
question_count?: number;
|
|
130
|
+
total_questions?: number;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Stats tracked per quiz when building the breakdown */
|
|
135
|
+
interface QuizBreakdownEntry {
|
|
136
|
+
results: FormattedQuizResult[];
|
|
137
|
+
stats: {
|
|
138
|
+
attempts: number;
|
|
139
|
+
averageScore: number;
|
|
140
|
+
passRate: number;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
5
143
|
|
|
6
144
|
/**
|
|
7
145
|
* Action to retrieve quiz/assessment results from LearnWorlds
|
|
8
146
|
*/
|
|
9
147
|
@RegisterClass(BaseAction, 'GetQuizResultsAction')
|
|
10
148
|
export class GetQuizResultsAction extends LearnWorldsBaseAction {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// Process each quiz result
|
|
102
|
-
for (const result of results) {
|
|
103
|
-
const formattedResult: any = {
|
|
104
|
-
id: result.id || result.result_id,
|
|
105
|
-
userId: result.user_id || userId,
|
|
106
|
-
courseId: result.course_id || courseId,
|
|
107
|
-
quizId: result.quiz_id || quizId,
|
|
108
|
-
attemptNumber: result.attempt_number || result.attempt || 1,
|
|
109
|
-
score: result.score || 0,
|
|
110
|
-
maxScore: result.max_score || result.total_points || 100,
|
|
111
|
-
percentage: result.percentage || ((result.score / (result.max_score || 100)) * 100),
|
|
112
|
-
passed: result.passed || result.is_passing || false,
|
|
113
|
-
passingScore: result.passing_score || result.passing_percentage || 70,
|
|
114
|
-
startedAt: result.started_at,
|
|
115
|
-
completedAt: result.completed_at || result.submitted_at,
|
|
116
|
-
duration: result.duration || result.time_spent,
|
|
117
|
-
durationText: this.formatDuration(result.duration || result.time_spent || 0)
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// Add user info if available
|
|
121
|
-
if (result.user && !formattedResult.user) {
|
|
122
|
-
formattedResult.user = {
|
|
123
|
-
id: result.user.id,
|
|
124
|
-
email: result.user.email,
|
|
125
|
-
name: result.user.name || `${result.user.first_name || ''} ${result.user.last_name || ''}`.trim()
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Add quiz info if available
|
|
130
|
-
if (result.quiz) {
|
|
131
|
-
formattedResult.quiz = {
|
|
132
|
-
id: result.quiz.id,
|
|
133
|
-
title: result.quiz.title || result.quiz.name,
|
|
134
|
-
type: result.quiz.type || 'quiz',
|
|
135
|
-
questionCount: result.quiz.question_count || result.quiz.total_questions
|
|
136
|
-
};
|
|
137
|
-
} else if (!quizId && result.quiz_id) {
|
|
138
|
-
// Try to get quiz info
|
|
139
|
-
const quizResponse = await this.makeLearnWorldsRequest(
|
|
140
|
-
`/quizzes/${result.quiz_id}`,
|
|
141
|
-
'GET',
|
|
142
|
-
null,
|
|
143
|
-
ContextUser
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
if (quizResponse.success && quizResponse.data) {
|
|
147
|
-
const quiz = quizResponse.data;
|
|
148
|
-
formattedResult.quiz = {
|
|
149
|
-
id: quiz.id,
|
|
150
|
-
title: quiz.title || quiz.name,
|
|
151
|
-
type: quiz.type || 'quiz',
|
|
152
|
-
questionCount: quiz.question_count || quiz.total_questions
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Add questions and answers if requested
|
|
158
|
-
if (includeQuestions || includeAnswers) {
|
|
159
|
-
const detailsResponse = await this.makeLearnWorldsRequest(
|
|
160
|
-
`/quiz-results/${formattedResult.id}/details`,
|
|
161
|
-
'GET',
|
|
162
|
-
null,
|
|
163
|
-
ContextUser
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
if (detailsResponse.success && detailsResponse.data) {
|
|
167
|
-
const details = detailsResponse.data;
|
|
168
|
-
|
|
169
|
-
if (includeQuestions) {
|
|
170
|
-
formattedResult.questions = this.formatQuestions(details.questions || details.answers || []);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (includeAnswers) {
|
|
174
|
-
formattedResult.answers = this.formatAnswers(details.answers || details.questions || []);
|
|
175
|
-
|
|
176
|
-
// Calculate additional metrics
|
|
177
|
-
const answers = formattedResult.answers || [];
|
|
178
|
-
formattedResult.metrics = {
|
|
179
|
-
correctAnswers: answers.filter((a: any) => a.isCorrect).length,
|
|
180
|
-
incorrectAnswers: answers.filter((a: any) => !a.isCorrect).length,
|
|
181
|
-
totalQuestions: answers.length,
|
|
182
|
-
accuracyRate: answers.length > 0
|
|
183
|
-
? (answers.filter((a: any) => a.isCorrect).length / answers.length * 100).toFixed(1)
|
|
184
|
-
: 0
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
formattedResults.push(formattedResult);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Calculate summary statistics
|
|
194
|
-
const totalResults = formattedResults.length;
|
|
195
|
-
const passedResults = formattedResults.filter(r => r.passed).length;
|
|
196
|
-
const averageScore = totalResults > 0
|
|
197
|
-
? formattedResults.reduce((sum, r) => sum + r.percentage, 0) / totalResults
|
|
198
|
-
: 0;
|
|
199
|
-
const averageDuration = totalResults > 0
|
|
200
|
-
? formattedResults.reduce((sum, r) => sum + (r.duration || 0), 0) / totalResults
|
|
201
|
-
: 0;
|
|
202
|
-
|
|
203
|
-
// Group results by quiz if multiple quizzes
|
|
204
|
-
const resultsByQuiz: any = {};
|
|
205
|
-
if (!quizId) {
|
|
206
|
-
formattedResults.forEach(result => {
|
|
207
|
-
const quizTitle = result.quiz?.title || 'Unknown Quiz';
|
|
208
|
-
if (!resultsByQuiz[quizTitle]) {
|
|
209
|
-
resultsByQuiz[quizTitle] = {
|
|
210
|
-
results: [],
|
|
211
|
-
stats: {
|
|
212
|
-
attempts: 0,
|
|
213
|
-
averageScore: 0,
|
|
214
|
-
passRate: 0
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
resultsByQuiz[quizTitle].results.push(result);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
// Calculate stats for each quiz
|
|
222
|
-
Object.keys(resultsByQuiz).forEach(quizTitle => {
|
|
223
|
-
const quizResults = resultsByQuiz[quizTitle].results;
|
|
224
|
-
resultsByQuiz[quizTitle].stats = {
|
|
225
|
-
attempts: quizResults.length,
|
|
226
|
-
averageScore: (quizResults.reduce((sum: number, r: any) => sum + r.percentage, 0) / quizResults.length).toFixed(1),
|
|
227
|
-
passRate: ((quizResults.filter((r: any) => r.passed).length / quizResults.length) * 100).toFixed(1)
|
|
228
|
-
};
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Create summary
|
|
233
|
-
const summary = {
|
|
234
|
-
totalResults: totalResults,
|
|
235
|
-
passedResults: passedResults,
|
|
236
|
-
failedResults: totalResults - passedResults,
|
|
237
|
-
passRate: totalResults > 0 ? ((passedResults / totalResults) * 100).toFixed(1) : 0,
|
|
238
|
-
averageScore: averageScore.toFixed(1),
|
|
239
|
-
averageDuration: averageDuration,
|
|
240
|
-
averageDurationText: this.formatDuration(Math.round(averageDuration)),
|
|
241
|
-
dateRange: {
|
|
242
|
-
from: dateFrom || 'all-time',
|
|
243
|
-
to: dateTo || 'current'
|
|
244
|
-
},
|
|
245
|
-
filterType: userId ? (courseId ? 'user-course' : 'user') : (courseId ? 'course' : 'all'),
|
|
246
|
-
quizBreakdown: !quizId ? resultsByQuiz : null
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
// Update output parameters
|
|
250
|
-
const outputParams = [...Params];
|
|
251
|
-
const quizResultsParam = outputParams.find(p => p.Name === 'QuizResults');
|
|
252
|
-
if (quizResultsParam) {
|
|
253
|
-
quizResultsParam.Value = formattedResults;
|
|
254
|
-
}
|
|
255
|
-
const totalCountParam = outputParams.find(p => p.Name === 'TotalCount');
|
|
256
|
-
if (totalCountParam) {
|
|
257
|
-
totalCountParam.Value = totalResults;
|
|
258
|
-
}
|
|
259
|
-
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
260
|
-
if (summaryParam) {
|
|
261
|
-
summaryParam.Value = summary;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return {
|
|
265
|
-
Success: true,
|
|
266
|
-
ResultCode: 'SUCCESS',
|
|
267
|
-
Message: `Retrieved ${totalResults} quiz result(s)`,
|
|
268
|
-
Params: outputParams
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
} catch (error) {
|
|
272
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
273
|
-
return {
|
|
274
|
-
Success: false,
|
|
275
|
-
ResultCode: 'EXECUTION_ERROR',
|
|
276
|
-
Message: `Error retrieving quiz results: ${errorMessage}`,
|
|
277
|
-
Params
|
|
278
|
-
};
|
|
279
|
-
}
|
|
149
|
+
// ----------------------------------------------------------------
|
|
150
|
+
// Typed public method – can be called directly from code
|
|
151
|
+
// ----------------------------------------------------------------
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get quiz results for a user, course, or specific quiz.
|
|
155
|
+
* Throws on any error.
|
|
156
|
+
*/
|
|
157
|
+
public async GetQuizResults(params: GetQuizResultsParams, contextUser: UserInfo): Promise<GetQuizResultsResult> {
|
|
158
|
+
this.SetCompanyContext(params.CompanyID);
|
|
159
|
+
|
|
160
|
+
const {
|
|
161
|
+
UserID: userId,
|
|
162
|
+
CourseID: courseId,
|
|
163
|
+
QuizID: quizId,
|
|
164
|
+
IncludeQuestions: includeQuestionsRaw,
|
|
165
|
+
IncludeAnswers: includeAnswersRaw,
|
|
166
|
+
PassingOnly: passingOnly = false,
|
|
167
|
+
DateFrom: dateFrom,
|
|
168
|
+
DateTo: dateTo,
|
|
169
|
+
SortBy: sortBy = 'completed_at',
|
|
170
|
+
SortOrder: sortOrder = 'desc',
|
|
171
|
+
MaxResults: maxResults = 100,
|
|
172
|
+
} = params;
|
|
173
|
+
|
|
174
|
+
const includeQuestions = includeQuestionsRaw !== false;
|
|
175
|
+
const includeAnswers = includeAnswersRaw !== false;
|
|
176
|
+
|
|
177
|
+
// Require at least one identifier
|
|
178
|
+
if (!userId && !courseId && !quizId) {
|
|
179
|
+
throw new Error('At least one of UserID, CourseID, or QuizID is required');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Build query parameters
|
|
183
|
+
const queryParams = this.buildQuizQueryParams(userId, quizId, passingOnly, dateFrom, dateTo, sortBy, sortOrder, maxResults);
|
|
184
|
+
|
|
185
|
+
// Validate path segments before URL interpolation
|
|
186
|
+
if (userId) this.validatePathSegment(userId, 'UserID');
|
|
187
|
+
if (courseId) this.validatePathSegment(courseId, 'CourseID');
|
|
188
|
+
if (quizId) this.validatePathSegment(quizId, 'QuizID');
|
|
189
|
+
|
|
190
|
+
// Determine endpoint
|
|
191
|
+
const endpoint = this.buildQuizEndpoint(userId, courseId, quizId);
|
|
192
|
+
|
|
193
|
+
// Build query string
|
|
194
|
+
const queryString = this.buildQueryString(queryParams);
|
|
195
|
+
|
|
196
|
+
// Fetch quiz results
|
|
197
|
+
const resultsResponse = await this.makeLearnWorldsRequest<LWQuizResultsApiResponse>(endpoint + queryString, 'GET', null, contextUser);
|
|
198
|
+
|
|
199
|
+
if (resultsResponse.success === false) {
|
|
200
|
+
throw new Error(resultsResponse.message || 'Failed to retrieve quiz results');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Normalize results
|
|
204
|
+
const rawResults = this.extractQuizResultsArray(resultsResponse);
|
|
205
|
+
|
|
206
|
+
// Process each quiz result
|
|
207
|
+
const formattedResults = await this.processQuizResults(rawResults, userId, courseId, quizId, includeQuestions, includeAnswers, contextUser);
|
|
208
|
+
|
|
209
|
+
// Calculate summary
|
|
210
|
+
const summary = this.buildQuizResultsSummary(formattedResults, userId, courseId, quizId, dateFrom, dateTo);
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
QuizResults: formattedResults,
|
|
214
|
+
TotalCount: formattedResults.length,
|
|
215
|
+
Summary: summary,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// ----------------------------------------------------------------
|
|
220
|
+
// Framework wrapper – thin delegation to the public method
|
|
221
|
+
// ----------------------------------------------------------------
|
|
222
|
+
|
|
223
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
224
|
+
const { Params, ContextUser } = params;
|
|
225
|
+
this.params = Params;
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
const typedParams = this.extractQuizResultsParams(Params);
|
|
229
|
+
const result = await this.GetQuizResults(typedParams, ContextUser);
|
|
230
|
+
|
|
231
|
+
this.setOutputParam(Params, 'QuizResults', result.QuizResults);
|
|
232
|
+
this.setOutputParam(Params, 'TotalCount', result.TotalCount);
|
|
233
|
+
this.setOutputParam(Params, 'Summary', result.Summary);
|
|
234
|
+
|
|
235
|
+
return this.buildSuccessResult(`Retrieved ${result.TotalCount} quiz result(s)`, Params);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
238
|
+
return this.buildErrorResult('ERROR', `Error retrieving quiz results: ${msg}`, Params);
|
|
280
239
|
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ----------------------------------------------------------------
|
|
243
|
+
// Private helpers – parameter extraction
|
|
244
|
+
// ----------------------------------------------------------------
|
|
245
|
+
|
|
246
|
+
private extractQuizResultsParams(params: ActionParam[]): GetQuizResultsParams {
|
|
247
|
+
return {
|
|
248
|
+
CompanyID: this.getRequiredStringParam(params, 'CompanyID'),
|
|
249
|
+
UserID: this.getOptionalStringParam(params, 'UserID'),
|
|
250
|
+
CourseID: this.getOptionalStringParam(params, 'CourseID'),
|
|
251
|
+
QuizID: this.getOptionalStringParam(params, 'QuizID'),
|
|
252
|
+
IncludeQuestions: this.getOptionalBooleanParam(params, 'IncludeQuestions', true),
|
|
253
|
+
IncludeAnswers: this.getOptionalBooleanParam(params, 'IncludeAnswers', true),
|
|
254
|
+
PassingOnly: this.getOptionalBooleanParam(params, 'PassingOnly', false),
|
|
255
|
+
DateFrom: this.getOptionalStringParam(params, 'DateFrom'),
|
|
256
|
+
DateTo: this.getOptionalStringParam(params, 'DateTo'),
|
|
257
|
+
SortBy: this.getOptionalStringParam(params, 'SortBy'),
|
|
258
|
+
SortOrder: (this.getOptionalStringParam(params, 'SortOrder') || 'desc') as 'asc' | 'desc',
|
|
259
|
+
MaxResults: this.getOptionalNumberParam(params, 'MaxResults', LearnWorldsBaseAction.LW_MAX_PAGE_SIZE),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ----------------------------------------------------------------
|
|
264
|
+
// Private helpers – query building
|
|
265
|
+
// ----------------------------------------------------------------
|
|
281
266
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
267
|
+
private buildQuizQueryParams(
|
|
268
|
+
userId: string | undefined,
|
|
269
|
+
quizId: string | undefined,
|
|
270
|
+
passingOnly: boolean,
|
|
271
|
+
dateFrom: string | undefined,
|
|
272
|
+
dateTo: string | undefined,
|
|
273
|
+
sortBy: string,
|
|
274
|
+
sortOrder: string,
|
|
275
|
+
maxResults: number,
|
|
276
|
+
): LWQuizResultQueryParams {
|
|
277
|
+
const queryParams: LWQuizResultQueryParams = {
|
|
278
|
+
limit: Math.min(maxResults, LearnWorldsBaseAction.LW_MAX_PAGE_SIZE),
|
|
279
|
+
sort: sortBy,
|
|
280
|
+
order: sortOrder,
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
if (passingOnly) {
|
|
284
|
+
queryParams.passed = true;
|
|
285
|
+
}
|
|
286
|
+
const parsedFrom = this.safeParseDateToISO(dateFrom);
|
|
287
|
+
if (parsedFrom) {
|
|
288
|
+
queryParams.completed_after = parsedFrom;
|
|
289
|
+
}
|
|
290
|
+
const parsedTo = this.safeParseDateToISO(dateTo);
|
|
291
|
+
if (parsedTo) {
|
|
292
|
+
queryParams.completed_before = parsedTo;
|
|
294
293
|
}
|
|
294
|
+
if (quizId && userId) {
|
|
295
|
+
queryParams.user_id = userId;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return queryParams;
|
|
299
|
+
}
|
|
295
300
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
isCorrect: a.is_correct || a.correct || false,
|
|
306
|
-
pointsEarned: a.points_earned || (a.is_correct ? (a.points || 1) : 0),
|
|
307
|
-
pointsPossible: a.points_possible || a.points || 1,
|
|
308
|
-
feedback: a.feedback,
|
|
309
|
-
timeSpent: a.time_spent,
|
|
310
|
-
answeredAt: a.answered_at
|
|
311
|
-
}));
|
|
301
|
+
private buildQuizEndpoint(userId: string | undefined, courseId: string | undefined, quizId: string | undefined): string {
|
|
302
|
+
if (quizId) {
|
|
303
|
+
return `/quizzes/${quizId}/results`;
|
|
304
|
+
} else if (userId && courseId) {
|
|
305
|
+
return `/users/${userId}/courses/${courseId}/quiz-results`;
|
|
306
|
+
} else if (userId) {
|
|
307
|
+
return `/users/${userId}/quiz-results`;
|
|
308
|
+
} else if (courseId) {
|
|
309
|
+
return `/courses/${courseId}/quiz-results`;
|
|
312
310
|
}
|
|
311
|
+
return '/quiz-results';
|
|
312
|
+
}
|
|
313
313
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
{
|
|
321
|
-
Name: 'UserID',
|
|
322
|
-
Type: 'Input',
|
|
323
|
-
Value: null
|
|
324
|
-
},
|
|
325
|
-
{
|
|
326
|
-
Name: 'CourseID',
|
|
327
|
-
Type: 'Input',
|
|
328
|
-
Value: null
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
Name: 'QuizID',
|
|
332
|
-
Type: 'Input',
|
|
333
|
-
Value: null
|
|
334
|
-
},
|
|
335
|
-
{
|
|
336
|
-
Name: 'IncludeQuestions',
|
|
337
|
-
Type: 'Input',
|
|
338
|
-
Value: true
|
|
339
|
-
},
|
|
340
|
-
{
|
|
341
|
-
Name: 'IncludeAnswers',
|
|
342
|
-
Type: 'Input',
|
|
343
|
-
Value: true
|
|
344
|
-
},
|
|
345
|
-
{
|
|
346
|
-
Name: 'PassingOnly',
|
|
347
|
-
Type: 'Input',
|
|
348
|
-
Value: false
|
|
349
|
-
},
|
|
350
|
-
{
|
|
351
|
-
Name: 'DateFrom',
|
|
352
|
-
Type: 'Input',
|
|
353
|
-
Value: null
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
Name: 'DateTo',
|
|
357
|
-
Type: 'Input',
|
|
358
|
-
Value: null
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
Name: 'SortBy',
|
|
362
|
-
Type: 'Input',
|
|
363
|
-
Value: 'completed_at'
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
Name: 'SortOrder',
|
|
367
|
-
Type: 'Input',
|
|
368
|
-
Value: 'desc'
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
Name: 'MaxResults',
|
|
372
|
-
Type: 'Input',
|
|
373
|
-
Value: 100
|
|
374
|
-
},
|
|
375
|
-
{
|
|
376
|
-
Name: 'QuizResults',
|
|
377
|
-
Type: 'Output',
|
|
378
|
-
Value: null
|
|
379
|
-
},
|
|
380
|
-
{
|
|
381
|
-
Name: 'TotalCount',
|
|
382
|
-
Type: 'Output',
|
|
383
|
-
Value: null
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
Name: 'Summary',
|
|
387
|
-
Type: 'Output',
|
|
388
|
-
Value: null
|
|
389
|
-
}
|
|
390
|
-
];
|
|
391
|
-
return [...baseParams, ...specificParams];
|
|
314
|
+
private buildQueryString(queryParams: Record<string, string | number | boolean | undefined>): string {
|
|
315
|
+
const filtered: Record<string, string> = {};
|
|
316
|
+
for (const [key, value] of Object.entries(queryParams)) {
|
|
317
|
+
if (value !== undefined) {
|
|
318
|
+
filtered[key] = String(value);
|
|
319
|
+
}
|
|
392
320
|
}
|
|
321
|
+
const keys = Object.keys(filtered);
|
|
322
|
+
if (keys.length === 0) return '';
|
|
323
|
+
return '?' + new URLSearchParams(filtered).toString();
|
|
324
|
+
}
|
|
393
325
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
326
|
+
private extractQuizResultsArray(response: LWQuizResultsApiResponse): LWRawQuizResult[] {
|
|
327
|
+
const data = response.data;
|
|
328
|
+
if (Array.isArray(data)) {
|
|
329
|
+
return data;
|
|
330
|
+
}
|
|
331
|
+
if (data && typeof data === 'object' && 'data' in data && Array.isArray(data.data)) {
|
|
332
|
+
return data.data;
|
|
399
333
|
}
|
|
400
|
-
|
|
334
|
+
return [];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// ----------------------------------------------------------------
|
|
338
|
+
// Private helpers – processing
|
|
339
|
+
// ----------------------------------------------------------------
|
|
340
|
+
|
|
341
|
+
private async processQuizResults(
|
|
342
|
+
rawResults: LWRawQuizResult[],
|
|
343
|
+
userId: string | undefined,
|
|
344
|
+
courseId: string | undefined,
|
|
345
|
+
quizId: string | undefined,
|
|
346
|
+
includeQuestions: boolean,
|
|
347
|
+
includeAnswers: boolean,
|
|
348
|
+
contextUser: UserInfo,
|
|
349
|
+
): Promise<FormattedQuizResult[]> {
|
|
350
|
+
const formatted: FormattedQuizResult[] = [];
|
|
351
|
+
|
|
352
|
+
for (const result of rawResults) {
|
|
353
|
+
const formattedResult = this.buildBaseQuizResult(result, userId, courseId, quizId);
|
|
354
|
+
|
|
355
|
+
// Attach user info if available
|
|
356
|
+
if (result.user) {
|
|
357
|
+
formattedResult.user = {
|
|
358
|
+
id: result.user.id || '',
|
|
359
|
+
email: result.user.email || '',
|
|
360
|
+
name: result.user.name || `${result.user.first_name || ''} ${result.user.last_name || ''}`.trim(),
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Attach quiz info
|
|
365
|
+
formattedResult.quiz = await this.resolveQuizInfo(result, quizId, contextUser);
|
|
366
|
+
|
|
367
|
+
// Attach questions & answers if requested
|
|
368
|
+
if (includeQuestions || includeAnswers) {
|
|
369
|
+
await this.attachDetailedResults(formattedResult, includeQuestions, includeAnswers, contextUser);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
formatted.push(formattedResult);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return formatted;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
private buildBaseQuizResult(
|
|
379
|
+
result: LWRawQuizResult,
|
|
380
|
+
userId: string | undefined,
|
|
381
|
+
courseId: string | undefined,
|
|
382
|
+
quizId: string | undefined,
|
|
383
|
+
): FormattedQuizResult {
|
|
384
|
+
const score = result.score || 0;
|
|
385
|
+
const maxScore = result.max_score || result.total_points || 100;
|
|
386
|
+
|
|
387
|
+
return {
|
|
388
|
+
id: result.id || result.result_id || '',
|
|
389
|
+
userId: result.user_id || userId || '',
|
|
390
|
+
courseId: result.course_id || courseId || '',
|
|
391
|
+
quizId: result.quiz_id || quizId || '',
|
|
392
|
+
attemptNumber: result.attempt_number || result.attempt || 1,
|
|
393
|
+
score,
|
|
394
|
+
maxScore,
|
|
395
|
+
percentage: result.percentage || (score / (maxScore || 100)) * 100,
|
|
396
|
+
passed: result.passed || result.is_passing || false,
|
|
397
|
+
passingScore: result.passing_score || result.passing_percentage || 70,
|
|
398
|
+
startedAt: result.started_at,
|
|
399
|
+
completedAt: result.completed_at || result.submitted_at,
|
|
400
|
+
duration: result.duration || result.time_spent || 0,
|
|
401
|
+
durationText: this.formatDuration(result.duration || result.time_spent || 0),
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
private async resolveQuizInfo(
|
|
406
|
+
result: LWRawQuizResult,
|
|
407
|
+
filterQuizId: string | undefined,
|
|
408
|
+
contextUser: UserInfo,
|
|
409
|
+
): Promise<{ id: string; title: string; type: string; questionCount?: number } | undefined> {
|
|
410
|
+
if (result.quiz) {
|
|
411
|
+
return {
|
|
412
|
+
id: result.quiz.id || '',
|
|
413
|
+
title: result.quiz.title || result.quiz.name || '',
|
|
414
|
+
type: result.quiz.type || 'quiz',
|
|
415
|
+
questionCount: result.quiz.question_count || result.quiz.total_questions,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (!filterQuizId && result.quiz_id) {
|
|
420
|
+
const quizResponse = await this.makeLearnWorldsRequest<LWQuizLookup>(`/quizzes/${result.quiz_id}`, 'GET', null, contextUser);
|
|
421
|
+
|
|
422
|
+
if (quizResponse.success !== false && quizResponse.data) {
|
|
423
|
+
const quiz = quizResponse.data;
|
|
424
|
+
return {
|
|
425
|
+
id: quiz.id || '',
|
|
426
|
+
title: quiz.title || quiz.name || '',
|
|
427
|
+
type: quiz.type || 'quiz',
|
|
428
|
+
questionCount: quiz.question_count || quiz.total_questions,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
private async attachDetailedResults(
|
|
437
|
+
formattedResult: FormattedQuizResult,
|
|
438
|
+
includeQuestions: boolean,
|
|
439
|
+
includeAnswers: boolean,
|
|
440
|
+
contextUser: UserInfo,
|
|
441
|
+
): Promise<void> {
|
|
442
|
+
const detailsResponse = await this.makeLearnWorldsRequest<LWQuizDetailResponse>(`/quiz-results/${formattedResult.id}/details`, 'GET', null, contextUser);
|
|
443
|
+
|
|
444
|
+
if (detailsResponse.success === false || !detailsResponse.data) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const details = detailsResponse.data;
|
|
449
|
+
|
|
450
|
+
if (includeQuestions) {
|
|
451
|
+
formattedResult.questions = this.formatQuestions(details.questions || details.answers || []);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (includeAnswers) {
|
|
455
|
+
formattedResult.answers = this.formatAnswers(details.answers || details.questions || []);
|
|
456
|
+
|
|
457
|
+
// Calculate additional metrics
|
|
458
|
+
const answers = formattedResult.answers;
|
|
459
|
+
formattedResult.metrics = this.calculateQuizMetrics(answers);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// ----------------------------------------------------------------
|
|
464
|
+
// Private helpers – formatting
|
|
465
|
+
// ----------------------------------------------------------------
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Format quiz questions
|
|
469
|
+
*/
|
|
470
|
+
private formatQuestions(questions: LWRawQuestion[]): FormattedQuestion[] {
|
|
471
|
+
return questions.map((q, index) => ({
|
|
472
|
+
questionNumber: q.question_number || index + 1,
|
|
473
|
+
questionId: q.question_id || q.id || '',
|
|
474
|
+
questionText: q.question_text || q.question || q.text || '',
|
|
475
|
+
questionType: q.question_type || q.type || 'multiple-choice',
|
|
476
|
+
points: q.points || q.score || 1,
|
|
477
|
+
difficulty: q.difficulty || 'medium',
|
|
478
|
+
}));
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Format user answers
|
|
483
|
+
*/
|
|
484
|
+
private formatAnswers(answers: LWRawAnswer[]): FormattedAnswer[] {
|
|
485
|
+
return answers.map((a, index) => ({
|
|
486
|
+
questionNumber: a.question_number || index + 1,
|
|
487
|
+
questionId: a.question_id,
|
|
488
|
+
userAnswer: this.coerceAnswerValue(a.user_answer || a.answer || a.selected_answer),
|
|
489
|
+
correctAnswer: this.coerceAnswerValue(a.correct_answer),
|
|
490
|
+
isCorrect: a.is_correct || a.correct || false,
|
|
491
|
+
pointsEarned: a.points_earned || (a.is_correct ? a.points || 1 : 0),
|
|
492
|
+
pointsPossible: a.points_possible || a.points || 1,
|
|
493
|
+
feedback: a.feedback,
|
|
494
|
+
timeSpent: a.time_spent,
|
|
495
|
+
answeredAt: a.answered_at,
|
|
496
|
+
}));
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Coerce a raw answer value from the API to a typed QuizAnswerValue.
|
|
501
|
+
*/
|
|
502
|
+
private coerceAnswerValue(value: unknown): QuizAnswerValue {
|
|
503
|
+
if (value === undefined || value === null) return undefined;
|
|
504
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return value;
|
|
505
|
+
if (Array.isArray(value)) return value.map(String);
|
|
506
|
+
return String(value);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
private calculateQuizMetrics(answers: FormattedAnswer[]): QuizMetrics {
|
|
510
|
+
const correctCount = answers.filter((a) => a.isCorrect).length;
|
|
511
|
+
return {
|
|
512
|
+
correctAnswers: correctCount,
|
|
513
|
+
incorrectAnswers: answers.filter((a) => !a.isCorrect).length,
|
|
514
|
+
totalQuestions: answers.length,
|
|
515
|
+
accuracyRate: answers.length > 0 ? Number(((correctCount / answers.length) * 100).toFixed(1)) : 0,
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// ----------------------------------------------------------------
|
|
520
|
+
// Private helpers – summary
|
|
521
|
+
// ----------------------------------------------------------------
|
|
522
|
+
|
|
523
|
+
private buildQuizResultsSummary(
|
|
524
|
+
formattedResults: FormattedQuizResult[],
|
|
525
|
+
userId: string | undefined,
|
|
526
|
+
courseId: string | undefined,
|
|
527
|
+
quizId: string | undefined,
|
|
528
|
+
dateFrom: string | undefined,
|
|
529
|
+
dateTo: string | undefined,
|
|
530
|
+
): QuizResultsSummary {
|
|
531
|
+
const totalResults = formattedResults.length;
|
|
532
|
+
const passedResults = formattedResults.filter((r) => r.passed).length;
|
|
533
|
+
|
|
534
|
+
const averageScore = totalResults > 0 ? formattedResults.reduce((sum, r) => sum + r.percentage, 0) / totalResults : 0;
|
|
535
|
+
|
|
536
|
+
const averageDuration = totalResults > 0 ? formattedResults.reduce((sum, r) => sum + (r.duration || 0), 0) / totalResults : 0;
|
|
537
|
+
|
|
538
|
+
// Group results by quiz if multiple quizzes
|
|
539
|
+
const quizBreakdown = !quizId ? this.buildQuizBreakdown(formattedResults) : null;
|
|
540
|
+
|
|
541
|
+
const filterType = userId ? (courseId ? 'user-course' : 'user') : courseId ? 'course' : 'all';
|
|
542
|
+
|
|
543
|
+
return {
|
|
544
|
+
totalResults,
|
|
545
|
+
passedResults,
|
|
546
|
+
failedResults: totalResults - passedResults,
|
|
547
|
+
passRate: totalResults > 0 ? Number(((passedResults / totalResults) * 100).toFixed(1)) : 0,
|
|
548
|
+
averageScore: Number(averageScore.toFixed(1)),
|
|
549
|
+
averageDuration,
|
|
550
|
+
averageDurationText: this.formatDuration(Math.round(averageDuration)),
|
|
551
|
+
dateRange: {
|
|
552
|
+
from: dateFrom || 'all-time',
|
|
553
|
+
to: dateTo || 'current',
|
|
554
|
+
},
|
|
555
|
+
filterType,
|
|
556
|
+
quizBreakdown,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
private buildQuizBreakdown(formattedResults: FormattedQuizResult[]): Record<string, QuizBreakdownEntry> {
|
|
561
|
+
const resultsByQuiz: Record<string, QuizBreakdownEntry> = {};
|
|
562
|
+
|
|
563
|
+
for (const result of formattedResults) {
|
|
564
|
+
const quizTitle = result.quiz?.title || 'Unknown Quiz';
|
|
565
|
+
if (!resultsByQuiz[quizTitle]) {
|
|
566
|
+
resultsByQuiz[quizTitle] = {
|
|
567
|
+
results: [],
|
|
568
|
+
stats: { attempts: 0, averageScore: 0, passRate: 0 },
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
resultsByQuiz[quizTitle].results.push(result);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// Calculate stats for each quiz
|
|
575
|
+
for (const quizTitle of Object.keys(resultsByQuiz)) {
|
|
576
|
+
const quizResults = resultsByQuiz[quizTitle].results;
|
|
577
|
+
const qTotal = quizResults.length;
|
|
578
|
+
const qPassed = quizResults.filter((r) => r.passed).length;
|
|
579
|
+
const qAvgScore = quizResults.reduce((sum, r) => sum + r.percentage, 0) / qTotal;
|
|
580
|
+
|
|
581
|
+
resultsByQuiz[quizTitle].stats = {
|
|
582
|
+
attempts: qTotal,
|
|
583
|
+
averageScore: Number(qAvgScore.toFixed(1)),
|
|
584
|
+
passRate: Number(((qPassed / qTotal) * 100).toFixed(1)),
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return resultsByQuiz;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// ----------------------------------------------------------------
|
|
592
|
+
// Params & Description metadata
|
|
593
|
+
// ----------------------------------------------------------------
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Define the parameters this action expects
|
|
597
|
+
*/
|
|
598
|
+
public get Params(): ActionParam[] {
|
|
599
|
+
const baseParams = this.getCommonLMSParams();
|
|
600
|
+
const specificParams: ActionParam[] = [
|
|
601
|
+
{ Name: 'UserID', Type: 'Input', Value: null },
|
|
602
|
+
{ Name: 'CourseID', Type: 'Input', Value: null },
|
|
603
|
+
{ Name: 'QuizID', Type: 'Input', Value: null },
|
|
604
|
+
{ Name: 'IncludeQuestions', Type: 'Input', Value: true },
|
|
605
|
+
{ Name: 'IncludeAnswers', Type: 'Input', Value: true },
|
|
606
|
+
{ Name: 'PassingOnly', Type: 'Input', Value: false },
|
|
607
|
+
{ Name: 'DateFrom', Type: 'Input', Value: null },
|
|
608
|
+
{ Name: 'DateTo', Type: 'Input', Value: null },
|
|
609
|
+
{ Name: 'SortBy', Type: 'Input', Value: 'completed_at' },
|
|
610
|
+
{ Name: 'SortOrder', Type: 'Input', Value: 'desc' },
|
|
611
|
+
{ Name: 'MaxResults', Type: 'Input', Value: 100 },
|
|
612
|
+
{ Name: 'QuizResults', Type: 'Output', Value: null },
|
|
613
|
+
{ Name: 'TotalCount', Type: 'Output', Value: null },
|
|
614
|
+
{ Name: 'Summary', Type: 'Output', Value: null },
|
|
615
|
+
];
|
|
616
|
+
return [...baseParams, ...specificParams];
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Metadata about this action
|
|
621
|
+
*/
|
|
622
|
+
public get Description(): string {
|
|
623
|
+
return 'Retrieves quiz and assessment results from LearnWorlds with detailed question/answer information';
|
|
624
|
+
}
|
|
625
|
+
}
|