Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 61aa25e

Browse files
authored
Merge pull request #209 from Wardormeur/bugfix/leran-upon-extend-possible-status
Add enrollment check based upon modules status instead of only the gl…
2 parents 42d3183 + 81d863f commit 61aa25e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/users/lms/award-badge.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var _ = require('lodash');
66
* Webhook handler to award badges based on courses
77
* Courses "Code" must correspond to the badge slug
88
* @param {Object} certificate contains all the info, header/user/course passed
9+
* ie: {"header":{"source":"LearnUpon","version":1,"webhookId":2213843,"attempt":2,"lastAttemptAt":"2016-09-01T10:33:32Z","webHookType":"course_completion","signature":"5736605a1627415455de6f7ca50e7e9d"},"user":{"userId":12345,"lastName":null,"firstName":null,"email":"qq@example.com","username":null,"customData":null},"enrollmentId":42,"courseId":42,"courseName":"CoderDojo Ethos: Implementation and Practice","courseReferenceCode":"coderdojo-ethos:-implementation-and-practice","courseMetaData":null,"modules":[{"id":42,"type":"scorm","name":"CoderDojo Ethos: Implementation and Practice","status":"passed","percentage":100.0,"dateCompleted":null,"attempts":null,"isKnowledgeCheck":false}],"credits":[],"courseAccessExpiresAt":null,"certification":false,"certificationName":null,"certExpiresAt":null,"wasRecertified":false,"dateEnrolled":"2016-08-29T12:02:38Z","dateStarted":"2016-09-01T10:30:50Z","dateCompleted":"2016-09-01T10:32:28Z","percentage":100,"enrollmentStatus":"passed","hasAttemptsRemaining":false}
910
*/
1011
function awardLMSBadge (args, cb) {
1112
var seneca = this;
@@ -14,10 +15,14 @@ function awardLMSBadge (args, cb) {
1415
var user = certif.user;
1516

1617
function checkTestStatus (waterfallCb) {
17-
if (certif.header.webHookType !== 'course_completion')
18-
return cb(null, 'Unhandled webhook');
19-
if (certif.enrollmentStatus !== 'passed' && certif.enrollmentStatus !== 'completed' )
20-
return cb(null, 'Unhandled status');
18+
if (certif.header.webHookType !== 'course_completion') {
19+
return cb(null, {ok: false, why: 'Unhandled webhook'});
20+
}
21+
if (!_.every(certif.modules, {'status': 'passed'}) &&
22+
!_.every(certif.modules, {'status': 'completed'}) &&
23+
!_.includes(['completed', 'passed'], certif.enrollmentStatus) ) {
24+
return cb(null, {ok: false, why: 'Unhandled status'});
25+
}
2126
waterfallCb(null, certif.courseReferenceCode);
2227
}
2328

0 commit comments

Comments
 (0)