@things-factory/learning 0.0.0-stage → 10.1.261
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/dist-client/bootstrap.d.ts +2 -0
- package/dist-client/bootstrap.js +4 -0
- package/dist-client/bootstrap.js.map +1 -0
- package/dist-client/components/learning-assign-form.d.ts +24 -0
- package/dist-client/components/learning-assign-form.js +77 -0
- package/dist-client/components/learning-assign-form.js.map +1 -0
- package/dist-client/components/learning-course-form.d.ts +29 -0
- package/dist-client/components/learning-course-form.js +104 -0
- package/dist-client/components/learning-course-form.js.map +1 -0
- package/dist-client/components/learning-material-form.d.ts +41 -0
- package/dist-client/components/learning-material-form.js +202 -0
- package/dist-client/components/learning-material-form.js.map +1 -0
- package/dist-client/components/learning-question-form.d.ts +33 -0
- package/dist-client/components/learning-question-form.js +142 -0
- package/dist-client/components/learning-question-form.js.map +1 -0
- package/dist-client/components/learning-todo.d.ts +12 -0
- package/dist-client/components/learning-todo.js +43 -0
- package/dist-client/components/learning-todo.js.map +1 -0
- package/dist-client/components/learning-unit-form.d.ts +44 -0
- package/dist-client/components/learning-unit-form.js +151 -0
- package/dist-client/components/learning-unit-form.js.map +1 -0
- package/dist-client/index.d.ts +2 -0
- package/dist-client/index.js +3 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/pages/learning-course-editor.d.ts +63 -0
- package/dist-client/pages/learning-course-editor.js +476 -0
- package/dist-client/pages/learning-course-editor.js.map +1 -0
- package/dist-client/pages/learning-course-list.d.ts +37 -0
- package/dist-client/pages/learning-course-list.js +92 -0
- package/dist-client/pages/learning-course-list.js.map +1 -0
- package/dist-client/pages/learning-enrollment-status.d.ts +65 -0
- package/dist-client/pages/learning-enrollment-status.js +211 -0
- package/dist-client/pages/learning-enrollment-status.js.map +1 -0
- package/dist-client/pages/learning-view.d.ts +63 -0
- package/dist-client/pages/learning-view.js +446 -0
- package/dist-client/pages/learning-view.js.map +1 -0
- package/dist-client/pages/my-learning.d.ts +22 -0
- package/dist-client/pages/my-learning.js +110 -0
- package/dist-client/pages/my-learning.js.map +1 -0
- package/dist-client/route.d.ts +1 -0
- package/dist-client/route.js +21 -0
- package/dist-client/route.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-client/utils/learning-api.d.ts +61 -0
- package/dist-client/utils/learning-api.js +85 -0
- package/dist-client/utils/learning-api.js.map +1 -0
- package/dist-client/utils/learning-words.d.ts +20 -0
- package/dist-client/utils/learning-words.js +22 -0
- package/dist-client/utils/learning-words.js.map +1 -0
- package/dist-client/utils/material-source.d.ts +12 -0
- package/dist-client/utils/material-source.js +77 -0
- package/dist-client/utils/material-source.js.map +1 -0
- package/dist-server/activities.d.ts +38 -0
- package/dist-server/activities.js +42 -0
- package/dist-server/activities.js.map +1 -0
- package/dist-server/ai-reads.d.ts +9 -0
- package/dist-server/ai-reads.js +70 -0
- package/dist-server/ai-reads.js.map +1 -0
- package/dist-server/attachment-reader.d.ts +1 -0
- package/dist-server/attachment-reader.js +23 -0
- package/dist-server/attachment-reader.js.map +1 -0
- package/dist-server/index.d.ts +4 -0
- package/dist-server/index.js +33 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/learning-subjects.d.ts +10 -0
- package/dist-server/learning-subjects.js +31 -0
- package/dist-server/learning-subjects.js.map +1 -0
- package/dist-server/role-tasks.d.ts +2 -0
- package/dist-server/role-tasks.js +17 -0
- package/dist-server/role-tasks.js.map +1 -0
- package/dist-server/service/course/course-mutation.d.ts +19 -0
- package/dist-server/service/course/course-mutation.js +177 -0
- package/dist-server/service/course/course-mutation.js.map +1 -0
- package/dist-server/service/course/course-query.d.ts +27 -0
- package/dist-server/service/course/course-query.js +183 -0
- package/dist-server/service/course/course-query.js.map +1 -0
- package/dist-server/service/course/course-question.d.ts +41 -0
- package/dist-server/service/course/course-question.js +116 -0
- package/dist-server/service/course/course-question.js.map +1 -0
- package/dist-server/service/course/course-rules.d.ts +51 -0
- package/dist-server/service/course/course-rules.js +93 -0
- package/dist-server/service/course/course-rules.js.map +1 -0
- package/dist-server/service/course/course-service.d.ts +72 -0
- package/dist-server/service/course/course-service.js +398 -0
- package/dist-server/service/course/course-service.js.map +1 -0
- package/dist-server/service/course/course-type.d.ts +56 -0
- package/dist-server/service/course/course-type.js +202 -0
- package/dist-server/service/course/course-type.js.map +1 -0
- package/dist-server/service/course/course-unit.d.ts +37 -0
- package/dist-server/service/course/course-unit.js +128 -0
- package/dist-server/service/course/course-unit.js.map +1 -0
- package/dist-server/service/course/course-version.d.ts +45 -0
- package/dist-server/service/course/course-version.js +151 -0
- package/dist-server/service/course/course-version.js.map +1 -0
- package/dist-server/service/course/course.d.ts +23 -0
- package/dist-server/service/course/course.js +92 -0
- package/dist-server/service/course/course.js.map +1 -0
- package/dist-server/service/course/index.d.ts +15 -0
- package/dist-server/service/course/index.js +25 -0
- package/dist-server/service/course/index.js.map +1 -0
- package/dist-server/service/course/material-audio.d.ts +1 -0
- package/dist-server/service/course/material-audio.js +43 -0
- package/dist-server/service/course/material-audio.js.map +1 -0
- package/dist-server/service/course/material-draft-mutation.d.ts +13 -0
- package/dist-server/service/course/material-draft-mutation.js +55 -0
- package/dist-server/service/course/material-draft-mutation.js.map +1 -0
- package/dist-server/service/course/material-draft-rules.d.ts +38 -0
- package/dist-server/service/course/material-draft-rules.js +83 -0
- package/dist-server/service/course/material-draft-rules.js.map +1 -0
- package/dist-server/service/course/material-draft-service.d.ts +15 -0
- package/dist-server/service/course/material-draft-service.js +162 -0
- package/dist-server/service/course/material-draft-service.js.map +1 -0
- package/dist-server/service/enrollment/enrollment-mutation.d.ts +11 -0
- package/dist-server/service/enrollment/enrollment-mutation.js +124 -0
- package/dist-server/service/enrollment/enrollment-mutation.js.map +1 -0
- package/dist-server/service/enrollment/enrollment-query.d.ts +24 -0
- package/dist-server/service/enrollment/enrollment-query.js +236 -0
- package/dist-server/service/enrollment/enrollment-query.js.map +1 -0
- package/dist-server/service/enrollment/enrollment-remind.d.ts +1 -0
- package/dist-server/service/enrollment/enrollment-remind.js +45 -0
- package/dist-server/service/enrollment/enrollment-remind.js.map +1 -0
- package/dist-server/service/enrollment/enrollment-service.d.ts +110 -0
- package/dist-server/service/enrollment/enrollment-service.js +427 -0
- package/dist-server/service/enrollment/enrollment-service.js.map +1 -0
- package/dist-server/service/enrollment/enrollment-status.d.ts +53 -0
- package/dist-server/service/enrollment/enrollment-status.js +194 -0
- package/dist-server/service/enrollment/enrollment-status.js.map +1 -0
- package/dist-server/service/enrollment/enrollment-type.d.ts +82 -0
- package/dist-server/service/enrollment/enrollment-type.js +293 -0
- package/dist-server/service/enrollment/enrollment-type.js.map +1 -0
- package/dist-server/service/enrollment/enrollment.d.ts +53 -0
- package/dist-server/service/enrollment/enrollment.js +191 -0
- package/dist-server/service/enrollment/enrollment.js.map +1 -0
- package/dist-server/service/enrollment/index.d.ts +15 -0
- package/dist-server/service/enrollment/index.js +26 -0
- package/dist-server/service/enrollment/index.js.map +1 -0
- package/dist-server/service/enrollment/learning-ai.d.ts +45 -0
- package/dist-server/service/enrollment/learning-ai.js +93 -0
- package/dist-server/service/enrollment/learning-ai.js.map +1 -0
- package/dist-server/service/enrollment/learning-documents.d.ts +7 -0
- package/dist-server/service/enrollment/learning-documents.js +159 -0
- package/dist-server/service/enrollment/learning-documents.js.map +1 -0
- package/dist-server/service/enrollment/learning-outcome.d.ts +10 -0
- package/dist-server/service/enrollment/learning-outcome.js +16 -0
- package/dist-server/service/enrollment/learning-outcome.js.map +1 -0
- package/dist-server/service/enrollment/progress-rules.d.ts +119 -0
- package/dist-server/service/enrollment/progress-rules.js +132 -0
- package/dist-server/service/enrollment/progress-rules.js.map +1 -0
- package/dist-server/service/enrollment/quiz-attempt.d.ts +34 -0
- package/dist-server/service/enrollment/quiz-attempt.js +105 -0
- package/dist-server/service/enrollment/quiz-attempt.js.map +1 -0
- package/dist-server/service/enrollment/unit-progress.d.ts +34 -0
- package/dist-server/service/enrollment/unit-progress.js +134 -0
- package/dist-server/service/enrollment/unit-progress.js.map +1 -0
- package/dist-server/service/index.d.ts +14 -0
- package/dist-server/service/index.js +43 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/package.json +57 -4
- package/things-factory.config.js +14 -0
- package/translations/en.json +278 -0
- package/translations/es.json +278 -0
- package/translations/ja.json +278 -0
- package/translations/ko.json +278 -0
- package/translations/ms.json +278 -0
- package/translations/zh.json +278 -0
- package/README.md +0 -3
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOpen = exports.certificateNoOf = exports.todayIn = exports.learningAddressOf = exports.DIRECT_SOURCE_KIND = void 0;
|
|
4
|
+
exports.enroll = enroll;
|
|
5
|
+
exports.withdraw = withdraw;
|
|
6
|
+
exports.cancelEnrollment = cancelEnrollment;
|
|
7
|
+
exports.learnersOf = learnersOf;
|
|
8
|
+
exports.enrollmentOf = enrollmentOf;
|
|
9
|
+
exports.myEnrollmentOf = myEnrollmentOf;
|
|
10
|
+
exports.shownVersionOf = shownVersionOf;
|
|
11
|
+
exports.progressesOf = progressesOf;
|
|
12
|
+
exports.missingFor = missingFor;
|
|
13
|
+
exports.recordTick = recordTick;
|
|
14
|
+
exports.acknowledgeEnrollment = acknowledgeEnrollment;
|
|
15
|
+
exports.forLearner = forLearner;
|
|
16
|
+
exports.startQuizAttempt = startQuizAttempt;
|
|
17
|
+
exports.submitQuizAttempt = submitQuizAttempt;
|
|
18
|
+
exports.completeIfMet = completeIfMet;
|
|
19
|
+
exports.myEnrollments = myEnrollments;
|
|
20
|
+
/*
|
|
21
|
+
* What the doors of enrolments do with the database (ADR-0194 decisions 5-8): enrolling people for whoever asks and
|
|
22
|
+
* withdrawing them, the to-do of each, the time the server counts from ticks, the quiz the server scores, the
|
|
23
|
+
* acknowledgement, and completing an enrolment with its evidence in the same transaction as the handler of whoever
|
|
24
|
+
* asked. Nothing here deletes an enrolment or its progress.
|
|
25
|
+
*/
|
|
26
|
+
const typeorm_1 = require("typeorm");
|
|
27
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
28
|
+
const organization_1 = require("@things-factory/organization");
|
|
29
|
+
const env_1 = require("@things-factory/env");
|
|
30
|
+
const translator_1 = require("@things-factory/i18n-base/translator");
|
|
31
|
+
const shell_1 = require("@things-factory/shell");
|
|
32
|
+
const worklist_1 = require("@things-factory/worklist");
|
|
33
|
+
const activities_1 = require("../../activities");
|
|
34
|
+
const course_question_1 = require("../course/course-question");
|
|
35
|
+
const course_unit_1 = require("../course/course-unit");
|
|
36
|
+
const course_version_1 = require("../course/course-version");
|
|
37
|
+
const course_service_1 = require("../course/course-service");
|
|
38
|
+
const enrollment_1 = require("./enrollment");
|
|
39
|
+
const learning_outcome_1 = require("./learning-outcome");
|
|
40
|
+
const progress_rules_1 = require("./progress-rules");
|
|
41
|
+
const quiz_attempt_1 = require("./quiz-attempt");
|
|
42
|
+
const unit_progress_1 = require("./unit-progress");
|
|
43
|
+
exports.DIRECT_SOURCE_KIND = 'learning.direct';
|
|
44
|
+
/** The learner's screen of one enrolment - where the to-do leads. */
|
|
45
|
+
const learningAddressOf = (enrollmentId) => `learning-view?id=${enrollmentId}`;
|
|
46
|
+
exports.learningAddressOf = learningAddressOf;
|
|
47
|
+
const todayIn = (domain, now = new Date()) => (0, shell_1.calendarDay)(domain?.timezone, now);
|
|
48
|
+
exports.todayIn = todayIn;
|
|
49
|
+
const notFound = () => new shell_1.Refusal('learning-not-found', {}, 'the record was not found. reload and try again.');
|
|
50
|
+
const isOpen = (status) => enrollment_1.OPEN_ENROLLMENT_STATUSES.includes(status);
|
|
51
|
+
exports.isOpen = isOpen;
|
|
52
|
+
/* ---------------------------------------------------------------- the to-do (decision 5) */
|
|
53
|
+
/** The to-do is issued as its own assignee: nobody else hands it out. worklist speaks its refusals through `t`. */
|
|
54
|
+
function todoContextOf(tx, domain, user) {
|
|
55
|
+
const t = (0, translator_1.translatorFor)(user.locale || 'ko');
|
|
56
|
+
return { state: { domain, user, tx }, t: (key, options) => t(key, options) };
|
|
57
|
+
}
|
|
58
|
+
/** Hands out 「<과정> 수강」 to the person, with the due day - nothing where the domain has not installed the to-do. */
|
|
59
|
+
async function issueTodo(tx, domain, enrollment, course, person) {
|
|
60
|
+
const activity = await tx.getRepository(worklist_1.Activity).findOne({ where: { domain: { id: domain.id }, name: activities_1.LEARNING_COURSE_ACTIVITY } });
|
|
61
|
+
if (!activity) {
|
|
62
|
+
env_1.logger.warn(`[learning] ${domain.subdomain}: the activity "${activities_1.LEARNING_COURSE_ACTIVITY}" is not installed - "${course.name}" not handed out`);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const t = (0, translator_1.translatorFor)(person.locale || 'ko');
|
|
66
|
+
const name = t('text.learning-todo-name', { course: course.name });
|
|
67
|
+
const headline = enrollment.dueOn ? t('text.learning-todo-headline', { dueOn: enrollment.dueOn }) : t('text.learning-todo-headline-no-due');
|
|
68
|
+
const dueAt = enrollment.dueOn ? dueAtOf(enrollment.dueOn, domain.timezone) : undefined;
|
|
69
|
+
const context = todoContextOf(tx, domain, person);
|
|
70
|
+
const input = { enrollmentId: enrollment.id, headline, address: (0, exports.learningAddressOf)(enrollment.id) };
|
|
71
|
+
const instance = await (0, worklist_1.issue)({ name, description: headline, activityId: activity.id, input, assignees: [], threadsMin: 0, dueAt }, context);
|
|
72
|
+
await (0, worklist_1.assign)({ id: instance.id, assignees: [person.email], dueAt, reason: name }, context);
|
|
73
|
+
return instance.id;
|
|
74
|
+
}
|
|
75
|
+
/** The end of the due day in the domain's time zone. */
|
|
76
|
+
function dueAtOf(dueOn, timezone) {
|
|
77
|
+
const end = new Date(`${dueOn}T23:59:59Z`);
|
|
78
|
+
const zone = timezone || 'UTC';
|
|
79
|
+
const asLocal = new Date(end.toLocaleString('en-US', { timeZone: zone }));
|
|
80
|
+
const asUtc = new Date(end.toLocaleString('en-US', { timeZone: 'UTC' }));
|
|
81
|
+
return new Date(end.getTime() - (asLocal.getTime() - asUtc.getTime()));
|
|
82
|
+
}
|
|
83
|
+
async function todoOpen(tx, instanceId) {
|
|
84
|
+
return (await tx.getRepository(worklist_1.ActivityThread).count({ where: { activityInstance: { id: instanceId }, state: (0, typeorm_1.In)(['assigned', 'started', 'unassigned']) } })) > 0;
|
|
85
|
+
}
|
|
86
|
+
/** Ends the to-do as done once the course is completed. */
|
|
87
|
+
async function completeTodo(tx, domain, enrollment, by) {
|
|
88
|
+
if (!enrollment.todoInstanceId || !(await todoOpen(tx, enrollment.todoInstanceId)))
|
|
89
|
+
return;
|
|
90
|
+
await (0, worklist_1.complete)({ id: enrollment.todoInstanceId, reason: 'course completed' }, todoContextOf(tx, domain, by));
|
|
91
|
+
}
|
|
92
|
+
/** Aborts the to-do of an enrolment withdrawn or cancelled. */
|
|
93
|
+
async function abortTodo(tx, domain, enrollment, by, reason) {
|
|
94
|
+
if (!enrollment.todoInstanceId || !(await todoOpen(tx, enrollment.todoInstanceId)))
|
|
95
|
+
return;
|
|
96
|
+
await (0, worklist_1.abort)({ id: enrollment.todoInstanceId, reason }, todoContextOf(tx, domain, by));
|
|
97
|
+
}
|
|
98
|
+
/* ---------------------------------------------------------------- enrolling and withdrawing (decision 7) */
|
|
99
|
+
/**
|
|
100
|
+
* Enrols people in a course for whoever asks (`source`), to be completed by `dueOn` - the server function a using module
|
|
101
|
+
* calls with the people it chose. One open enrolment per person, course and source: a person who has one is left with
|
|
102
|
+
* it. Each new enrolment hands out its to-do. Answers the open enrolments of everyone given.
|
|
103
|
+
*/
|
|
104
|
+
async function enroll(source, userIds, courseId, dueOn, context) {
|
|
105
|
+
const { domain, user, tx } = context.state;
|
|
106
|
+
if (!source?.kind)
|
|
107
|
+
throw new shell_1.Refusal('learning-source-required', {}, 'an enrolment names who asked for it');
|
|
108
|
+
if (dueOn && !/^\d{4}-\d{2}-\d{2}$/.test(dueOn))
|
|
109
|
+
throw new shell_1.Refusal('learning-due-invalid', {}, 'the due day is YYYY-MM-DD');
|
|
110
|
+
const course = await (0, course_service_1.courseOf)(tx, domain, courseId);
|
|
111
|
+
if (!(await (0, course_service_1.publishedVersionOf)(tx, domain, course.id)))
|
|
112
|
+
throw new shell_1.Refusal('learning-course-not-published', { course: course.name }, `${course.name} has no published version`);
|
|
113
|
+
const ids = [...new Set(userIds)].filter(Boolean);
|
|
114
|
+
if (!ids.length)
|
|
115
|
+
return [];
|
|
116
|
+
const people = await tx.getRepository(auth_base_1.User).find({ where: { id: (0, typeorm_1.In)(ids) }, relations: ['domains'] });
|
|
117
|
+
const sourceId = source.id ?? '';
|
|
118
|
+
const repository = tx.getRepository(enrollment_1.Enrollment);
|
|
119
|
+
const out = [];
|
|
120
|
+
for (const id of ids) {
|
|
121
|
+
const person = people.find(one => one.id === id);
|
|
122
|
+
if (!person || !(person.domains ?? []).some(one => one.id === domain.id))
|
|
123
|
+
throw new shell_1.Refusal('learning-learner-unknown', {}, 'a learner must be a user of this domain');
|
|
124
|
+
const open = await repository.findOne({ where: { domain: { id: domain.id }, user: { id }, course: { id: course.id }, sourceKind: source.kind, sourceId, status: (0, typeorm_1.In)(enrollment_1.OPEN_ENROLLMENT_STATUSES) } });
|
|
125
|
+
if (open) {
|
|
126
|
+
out.push(open);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const saved = await repository.save({ domain, user: person, course, dueOn: dueOn || null, sourceKind: source.kind, sourceId, status: enrollment_1.EnrollmentStatus.ASSIGNED, learnedSeconds: 0, attempts: 0, creator: user, updater: user });
|
|
130
|
+
const todo = await issueTodo(tx, domain, saved, course, person);
|
|
131
|
+
if (todo)
|
|
132
|
+
await repository.update(saved.id, { todoInstanceId: todo });
|
|
133
|
+
out.push((await repository.findOneBy({ id: saved.id })));
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Withdraws the open enrolments a source asked for - the record they were for was taken back. Each is cancelled with
|
|
139
|
+
* the reason and its to-do aborted; completed ones stay. Answers how many were withdrawn.
|
|
140
|
+
*/
|
|
141
|
+
async function withdraw(source, reason, context) {
|
|
142
|
+
const { domain, user, tx } = context.state;
|
|
143
|
+
const rows = await tx.getRepository(enrollment_1.Enrollment).find({ where: { domain: { id: domain.id }, sourceKind: source.kind, sourceId: source.id ?? '', status: (0, typeorm_1.In)(enrollment_1.OPEN_ENROLLMENT_STATUSES) } });
|
|
144
|
+
let count = 0;
|
|
145
|
+
for (const row of rows)
|
|
146
|
+
if (await cancelOpen(tx, domain, row, user, reason))
|
|
147
|
+
count++;
|
|
148
|
+
return count;
|
|
149
|
+
}
|
|
150
|
+
/** Cancels an open enrolment - claimed by an update only an open one matches, so a completion at the same time wins once. */
|
|
151
|
+
async function cancelOpen(tx, domain, row, by, reason) {
|
|
152
|
+
const claimed = await tx.getRepository(enrollment_1.Enrollment).update({ id: row.id, status: (0, typeorm_1.In)(enrollment_1.OPEN_ENROLLMENT_STATUSES) }, { status: enrollment_1.EnrollmentStatus.CANCELLED, cancelledAt: new Date(), cancelReason: reason, updater: by });
|
|
153
|
+
if (!claimed.affected)
|
|
154
|
+
return false;
|
|
155
|
+
await abortTodo(tx, domain, row, by, reason);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* A manager cancels an enrolment with a reason (decision 8). An open one is withdrawn; a completed one stays on record as
|
|
160
|
+
* cancelled - never deleted - and whoever asked for it is told in the same transaction.
|
|
161
|
+
*/
|
|
162
|
+
async function cancelEnrollment(id, reason, context) {
|
|
163
|
+
const { domain, user, tx } = context.state;
|
|
164
|
+
if (!reason?.trim())
|
|
165
|
+
throw new shell_1.Refusal('learning-cancel-reason-required', {}, 'say why it is cancelled');
|
|
166
|
+
const row = await enrollmentOf(tx, domain, id);
|
|
167
|
+
if (isOpen(row.status)) {
|
|
168
|
+
if (!(await cancelOpen(tx, domain, row, user, reason.trim())))
|
|
169
|
+
throw new shell_1.Refusal('learning-enrollment-moved', {}, 'the enrolment changed meanwhile - reload and try again');
|
|
170
|
+
}
|
|
171
|
+
else if (row.status === enrollment_1.EnrollmentStatus.COMPLETED) {
|
|
172
|
+
const claimed = await tx.getRepository(enrollment_1.Enrollment).update({ id: row.id, status: enrollment_1.EnrollmentStatus.COMPLETED }, { status: enrollment_1.EnrollmentStatus.CANCELLED, cancelledAt: new Date(), cancelReason: reason.trim(), updater: user });
|
|
173
|
+
if (!claimed.affected)
|
|
174
|
+
throw new shell_1.Refusal('learning-enrollment-moved', {}, 'the enrolment changed meanwhile - reload and try again');
|
|
175
|
+
await (0, learning_outcome_1.learningOutcomeOf)(row.sourceKind)?.cancelled?.((await enrollmentOf(tx, domain, id)), reason.trim(), context);
|
|
176
|
+
}
|
|
177
|
+
else
|
|
178
|
+
throw new shell_1.Refusal('learning-enrollment-cancelled', {}, 'the enrolment is cancelled already');
|
|
179
|
+
return await enrollmentOf(tx, domain, id);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The people an audience names now - the domain, departments with those under them, roles and people, by organization's
|
|
183
|
+
* one rule (ADR-0163). Each target must be of this domain.
|
|
184
|
+
*/
|
|
185
|
+
async function learnersOf(audiences, context) {
|
|
186
|
+
const { domain, tx } = context.state;
|
|
187
|
+
if (!audiences?.length)
|
|
188
|
+
throw new shell_1.Refusal('learning-audience-required', {}, 'pick who takes the course');
|
|
189
|
+
const departmentIds = [...(await (0, organization_1.departmentTreeOf)(domain, tx)).keys()];
|
|
190
|
+
const roleIds = (await (0, organization_1.domainRolesOf)(domain, undefined, tx)).map(one => one.id);
|
|
191
|
+
for (const target of audiences) {
|
|
192
|
+
const why = (0, organization_1.audienceTargetRefusal)(target, { domainId: domain.id, departmentIds, roleIds });
|
|
193
|
+
if (why)
|
|
194
|
+
throw new shell_1.Refusal('learning-audience-invalid', { target: target.targetName ?? target.targetId }, `${target.targetName ?? target.targetId} is not of this domain (${why})`);
|
|
195
|
+
}
|
|
196
|
+
return await (0, organization_1.audienceUserIds)(domain, audiences, tx);
|
|
197
|
+
}
|
|
198
|
+
/* ---------------------------------------------------------------- reading */
|
|
199
|
+
async function enrollmentOf(tx, domain, id) {
|
|
200
|
+
const row = id && /^[0-9a-f-]{36}$/i.test(id) ? await tx.getRepository(enrollment_1.Enrollment).findOne({ where: { id, domain: { id: domain.id } } }) : null;
|
|
201
|
+
if (!row)
|
|
202
|
+
throw notFound();
|
|
203
|
+
return row;
|
|
204
|
+
}
|
|
205
|
+
/** The request's own enrolment - one answer for "none" and "not yours". */
|
|
206
|
+
async function myEnrollmentOf(context, id, tx = (0, course_service_1.learningManagerOf)(context)) {
|
|
207
|
+
const row = await enrollmentOf(tx, context.state.domain, id);
|
|
208
|
+
if (row.userId !== context.state.user.id)
|
|
209
|
+
throw notFound();
|
|
210
|
+
return row;
|
|
211
|
+
}
|
|
212
|
+
/** The version an enrolment shows: its own once started, the published one before. */
|
|
213
|
+
async function shownVersionOf(tx, domain, enrollment) {
|
|
214
|
+
if (enrollment.versionId)
|
|
215
|
+
return await tx.getRepository(course_version_1.CourseVersion).findOne({ where: { id: enrollment.versionId }, withDeleted: true });
|
|
216
|
+
return await (0, course_service_1.publishedVersionOf)(tx, domain, enrollment.courseId);
|
|
217
|
+
}
|
|
218
|
+
async function progressesOf(tx, enrollmentId) {
|
|
219
|
+
return await tx.getRepository(unit_progress_1.UnitProgress).find({ where: { enrollment: { id: enrollmentId } } });
|
|
220
|
+
}
|
|
221
|
+
/** What still stands between an enrolment and its completion - nothing for a completed one. */
|
|
222
|
+
async function missingFor(tx, domain, enrollment) {
|
|
223
|
+
if (enrollment.status === enrollment_1.EnrollmentStatus.COMPLETED)
|
|
224
|
+
return [];
|
|
225
|
+
const version = await shownVersionOf(tx, domain, enrollment);
|
|
226
|
+
if (!version)
|
|
227
|
+
return ['units'];
|
|
228
|
+
const units = (await (0, course_service_1.unitsOf)(tx, version.id)).filter(progress_rules_1.counts);
|
|
229
|
+
const progress = await progressesOf(tx, enrollment.id);
|
|
230
|
+
const questions = version.passScore != null ? await tx.getRepository(course_question_1.CourseQuestion).count({ where: { version: { id: version.id } } }) : 0;
|
|
231
|
+
return (0, progress_rules_1.missingOf)({
|
|
232
|
+
units: units.length,
|
|
233
|
+
unitsDone: units.filter(unit => progress.some(one => one.unitId === unit.id && one.doneAt)).length,
|
|
234
|
+
learnedSeconds: enrollment.learnedSeconds,
|
|
235
|
+
minSeconds: version.minSeconds ?? 0,
|
|
236
|
+
quiz: version.passScore != null && questions > 0,
|
|
237
|
+
passed: enrollment.score != null && enrollment.score >= (version.passScore ?? 101),
|
|
238
|
+
acknowledgement: !!version.acknowledgement,
|
|
239
|
+
acknowledged: !!enrollment.acknowledgedAt
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/* ---------------------------------------------------------------- learning (decision 6) */
|
|
243
|
+
/** The enrolment, started if it was not: its version fixed to the one published now, in progress from now on. */
|
|
244
|
+
async function started(tx, domain, enrollment, user) {
|
|
245
|
+
if (enrollment.status === enrollment_1.EnrollmentStatus.CANCELLED)
|
|
246
|
+
throw new shell_1.Refusal('learning-enrollment-cancelled', {}, 'the enrolment is cancelled');
|
|
247
|
+
if (enrollment.versionId) {
|
|
248
|
+
if (enrollment.status === enrollment_1.EnrollmentStatus.ASSIGNED)
|
|
249
|
+
await tx.getRepository(enrollment_1.Enrollment).update({ id: enrollment.id, status: enrollment_1.EnrollmentStatus.ASSIGNED }, { status: enrollment_1.EnrollmentStatus.IN_PROGRESS, startedAt: new Date() });
|
|
250
|
+
return await enrollmentOf(tx, domain, enrollment.id);
|
|
251
|
+
}
|
|
252
|
+
const version = await (0, course_service_1.publishedVersionOf)(tx, domain, enrollment.courseId);
|
|
253
|
+
if (!version)
|
|
254
|
+
throw new shell_1.Refusal('learning-course-not-published', {}, 'the course has no published version');
|
|
255
|
+
await tx.getRepository(enrollment_1.Enrollment).update({ id: enrollment.id, status: (0, typeorm_1.In)(enrollment_1.OPEN_ENROLLMENT_STATUSES) }, { version, status: enrollment_1.EnrollmentStatus.IN_PROGRESS, startedAt: enrollment.startedAt ?? new Date(), updater: user });
|
|
256
|
+
return await enrollmentOf(tx, domain, enrollment.id);
|
|
257
|
+
}
|
|
258
|
+
async function unitOfVersion(tx, version, unitId) {
|
|
259
|
+
const unit = await tx.getRepository(course_unit_1.CourseUnit).findOne({ where: { id: unitId, version: { id: version.id } } });
|
|
260
|
+
if (!unit)
|
|
261
|
+
throw notFound();
|
|
262
|
+
return unit;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* One tick of the learner's screen on a unit (decision 6): the server adds the gap since the unit's last tick, at most
|
|
266
|
+
* 15 seconds and at most what the screen says, and refuses a video position ahead of what was watched. A total the
|
|
267
|
+
* screen sends is never taken. A unit that reaches its condition is done, and the enrolment is completed when nothing is
|
|
268
|
+
* missing any more.
|
|
269
|
+
*/
|
|
270
|
+
async function recordTick(enrollmentId, unitId, seconds, position, context, now = new Date()) {
|
|
271
|
+
const { domain, user, tx } = context.state;
|
|
272
|
+
let enrollment = await myEnrollmentOf(context, enrollmentId, tx);
|
|
273
|
+
enrollment = await started(tx, domain, enrollment, user);
|
|
274
|
+
const unit = await unitOfVersion(tx, { id: enrollment.versionId }, unitId);
|
|
275
|
+
if (unit.kind === course_unit_1.CourseUnitKind.LINK)
|
|
276
|
+
throw new shell_1.Refusal('learning-link-not-counted', {}, 'a link is not counted');
|
|
277
|
+
const repository = tx.getRepository(unit_progress_1.UnitProgress);
|
|
278
|
+
const progress = (await repository.findOne({ where: { enrollment: { id: enrollment.id }, unit: { id: unit.id } } })) ??
|
|
279
|
+
(await repository.save({ domain, enrollment, unit, learnedSeconds: 0, watchedSeconds: 0, positionSeconds: 0, pagesSeen: 0, pagesRead: 0, pageSeconds: 0, pageAt: 0, creator: user, updater: user }));
|
|
280
|
+
if (enrollment.status === enrollment_1.EnrollmentStatus.COMPLETED)
|
|
281
|
+
return { enrollment, progress };
|
|
282
|
+
const verdict = (0, progress_rules_1.tickVerdict)(progress, { seconds, position }, now, unit);
|
|
283
|
+
if ('refusal' in verdict) {
|
|
284
|
+
if (verdict.refusal === 'page-ahead')
|
|
285
|
+
throw new shell_1.Refusal('learning-page-ahead', { allowed: verdict.allowed }, `a page cannot be ahead of the one after the last read (${verdict.allowed})`);
|
|
286
|
+
throw new shell_1.Refusal('learning-position-ahead', { allowed: verdict.allowed }, `the video cannot be ahead of what was watched (${verdict.allowed} s)`);
|
|
287
|
+
}
|
|
288
|
+
progress.learnedSeconds += verdict.add;
|
|
289
|
+
progress.watchedSeconds = verdict.watchedSeconds;
|
|
290
|
+
progress.positionSeconds = verdict.positionSeconds;
|
|
291
|
+
progress.pagesSeen = verdict.pagesSeen;
|
|
292
|
+
progress.pagesRead = verdict.pagesRead;
|
|
293
|
+
progress.pageSeconds = verdict.pageSeconds;
|
|
294
|
+
progress.pageAt = verdict.pageAt;
|
|
295
|
+
progress.lastTickAt = now;
|
|
296
|
+
if (!progress.doneAt && (0, progress_rules_1.unitDone)(unit, progress))
|
|
297
|
+
progress.doneAt = now;
|
|
298
|
+
progress.updater = user;
|
|
299
|
+
await repository.save(progress);
|
|
300
|
+
if (verdict.add)
|
|
301
|
+
await tx.getRepository(enrollment_1.Enrollment).increment({ id: enrollment.id }, 'learnedSeconds', verdict.add);
|
|
302
|
+
/* Where the learner was - the course opens on this unit again (2026-11-08). */
|
|
303
|
+
if (enrollment.lastUnitId !== unit.id)
|
|
304
|
+
await tx.getRepository(enrollment_1.Enrollment).update({ id: enrollment.id }, { lastUnitId: unit.id });
|
|
305
|
+
enrollment = await completeIfMet(tx, domain, await enrollmentOf(tx, domain, enrollment.id), context);
|
|
306
|
+
return { enrollment, progress };
|
|
307
|
+
}
|
|
308
|
+
/** The learner confirms the version's acknowledgement - recorded once, when they did. */
|
|
309
|
+
async function acknowledgeEnrollment(enrollmentId, context) {
|
|
310
|
+
const { domain, user, tx } = context.state;
|
|
311
|
+
let enrollment = await started(tx, domain, await myEnrollmentOf(context, enrollmentId, tx), user);
|
|
312
|
+
const version = await shownVersionOf(tx, domain, enrollment);
|
|
313
|
+
if (!version?.acknowledgement)
|
|
314
|
+
throw new shell_1.Refusal('learning-no-acknowledgement', {}, 'the course asks for no acknowledgement');
|
|
315
|
+
if (!enrollment.acknowledgedAt)
|
|
316
|
+
await tx.getRepository(enrollment_1.Enrollment).update({ id: enrollment.id }, { acknowledgedAt: new Date(), updater: user });
|
|
317
|
+
return await completeIfMet(tx, domain, await enrollmentOf(tx, domain, enrollment.id), context);
|
|
318
|
+
}
|
|
319
|
+
/** The questions of an attempt as the learner is drawn them - the choices in the order shown, never whether one is right. */
|
|
320
|
+
function forLearner(attempt, questions) {
|
|
321
|
+
return {
|
|
322
|
+
attempt,
|
|
323
|
+
questions: attempt.drawn.map(drawn => {
|
|
324
|
+
const question = questions.find(one => one.id === drawn.questionId);
|
|
325
|
+
return {
|
|
326
|
+
id: question.id,
|
|
327
|
+
kind: question.kind,
|
|
328
|
+
text: question.text,
|
|
329
|
+
choices: drawn.choiceIds.map(id => question.choices.find(one => one.id === id)).map(one => ({ id: one.id, text: one.text }))
|
|
330
|
+
};
|
|
331
|
+
})
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Starts an attempt at the quiz: the questions drawn and shuffled, their choices shuffled. An attempt not sent yet is
|
|
336
|
+
* answered again; the version's limit on attempts holds.
|
|
337
|
+
*/
|
|
338
|
+
/**
|
|
339
|
+
* Holds the enrolment for the rest of the request's transaction - an update takes its row lock on every driver, so two
|
|
340
|
+
* attempts of one enrolment are started, counted and sent one after the other. Two starts at once made two unsent
|
|
341
|
+
* attempts, and a limit of one let both be sent (2026-11-08).
|
|
342
|
+
*/
|
|
343
|
+
async function holdEnrollment(tx, domain, enrollment, user) {
|
|
344
|
+
await tx.getRepository(enrollment_1.Enrollment).update({ id: enrollment.id }, { updater: user });
|
|
345
|
+
return await enrollmentOf(tx, domain, enrollment.id);
|
|
346
|
+
}
|
|
347
|
+
async function startQuizAttempt(enrollmentId, context) {
|
|
348
|
+
const { domain, user, tx } = context.state;
|
|
349
|
+
const held = await holdEnrollment(tx, domain, await myEnrollmentOf(context, enrollmentId, tx), user);
|
|
350
|
+
const enrollment = await started(tx, domain, held, user);
|
|
351
|
+
if (enrollment.status === enrollment_1.EnrollmentStatus.COMPLETED)
|
|
352
|
+
throw new shell_1.Refusal('learning-enrollment-completed', {}, 'the course is completed');
|
|
353
|
+
const version = (await shownVersionOf(tx, domain, enrollment));
|
|
354
|
+
const questions = await (0, course_service_1.questionsOf)(tx, version.id);
|
|
355
|
+
if (version.passScore == null || !questions.length)
|
|
356
|
+
throw new shell_1.Refusal('learning-no-quiz', {}, 'the course has no quiz');
|
|
357
|
+
const repository = tx.getRepository(quiz_attempt_1.QuizAttempt);
|
|
358
|
+
const pending = await repository.findOne({ where: { enrollment: { id: enrollment.id }, submittedAt: (0, typeorm_1.IsNull)() } });
|
|
359
|
+
if (pending)
|
|
360
|
+
return forLearner(pending, questions);
|
|
361
|
+
if (version.attemptLimit != null && enrollment.attempts >= version.attemptLimit)
|
|
362
|
+
throw new shell_1.Refusal('learning-attempts-used', { limit: version.attemptLimit }, `all ${version.attemptLimit} attempts are used`);
|
|
363
|
+
const attempt = await repository.save({ domain, enrollment, drawn: (0, progress_rules_1.drawQuestions)(questions, version.questionCount), creator: user, updater: user });
|
|
364
|
+
return forLearner(attempt, questions);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Scores an attempt's answers on the server against what it drew (decision 4) - only the score and whether it passed go
|
|
368
|
+
* back, never the right answers. The best score stays on the enrolment; passing may complete it.
|
|
369
|
+
*/
|
|
370
|
+
async function submitQuizAttempt(attemptId, answers, context) {
|
|
371
|
+
const { domain, user, tx } = context.state;
|
|
372
|
+
const attempt = await tx.getRepository(quiz_attempt_1.QuizAttempt).findOne({ where: { id: attemptId, domain: { id: domain.id } } });
|
|
373
|
+
if (!attempt)
|
|
374
|
+
throw notFound();
|
|
375
|
+
const enrollment = await holdEnrollment(tx, domain, await myEnrollmentOf(context, attempt.enrollmentId, tx), user);
|
|
376
|
+
const version = (await shownVersionOf(tx, domain, enrollment));
|
|
377
|
+
if (version.attemptLimit != null && enrollment.attempts >= version.attemptLimit)
|
|
378
|
+
throw new shell_1.Refusal('learning-attempts-used', { limit: version.attemptLimit }, `all ${version.attemptLimit} attempts are used`);
|
|
379
|
+
const questions = await (0, course_service_1.questionsOf)(tx, version.id);
|
|
380
|
+
const drawn = attempt.drawn.map(one => questions.find(question => question.id === one.questionId)).filter(Boolean);
|
|
381
|
+
const kept = Object.fromEntries(drawn.map(question => [question.id, (answers?.[question.id] ?? []).map(String)]));
|
|
382
|
+
const score = (0, progress_rules_1.scoreOf)(drawn, kept);
|
|
383
|
+
const passed = score >= (version.passScore ?? 101);
|
|
384
|
+
const claimed = await tx.getRepository(quiz_attempt_1.QuizAttempt).update({ id: attempt.id, submittedAt: (0, typeorm_1.IsNull)() }, { answers: kept, score, passed, submittedAt: new Date(), updater: user });
|
|
385
|
+
if (!claimed.affected)
|
|
386
|
+
throw new shell_1.Refusal('learning-attempt-sent', {}, 'the attempt was sent already');
|
|
387
|
+
await tx.getRepository(enrollment_1.Enrollment).increment({ id: enrollment.id }, 'attempts', 1);
|
|
388
|
+
await tx.getRepository(enrollment_1.Enrollment).update({ id: enrollment.id }, { score: Math.max(enrollment.score ?? 0, score), updater: user });
|
|
389
|
+
const after = await completeIfMet(tx, domain, await enrollmentOf(tx, domain, enrollment.id), context);
|
|
390
|
+
return { enrollment: after, score, passed, attemptsLeft: version.attemptLimit != null ? Math.max(0, version.attemptLimit - after.attempts) : null };
|
|
391
|
+
}
|
|
392
|
+
/* ---------------------------------------------------------------- completing (decision 8) */
|
|
393
|
+
/** A certificate number: the day completed and the enrolment's own id - one per completion, never reused. */
|
|
394
|
+
const certificateNoOf = (enrollment, day) => `LMS-${day.replace(/-/g, '')}-${enrollment.id.replace(/-/g, '').slice(0, 8).toUpperCase()}`;
|
|
395
|
+
exports.certificateNoOf = certificateNoOf;
|
|
396
|
+
/**
|
|
397
|
+
* Completes an open enrolment when nothing is missing - every unit done, the least time, the quiz passed, the
|
|
398
|
+
* acknowledgement confirmed. The evidence stays on it; whoever asked for it is told in this same transaction (a handler
|
|
399
|
+
* that fails takes the completion back), and the to-do ends as done.
|
|
400
|
+
*/
|
|
401
|
+
async function completeIfMet(tx, domain, enrollment, context) {
|
|
402
|
+
if (!isOpen(enrollment.status) || !enrollment.versionId)
|
|
403
|
+
return enrollment;
|
|
404
|
+
if ((await missingFor(tx, domain, enrollment)).length)
|
|
405
|
+
return enrollment;
|
|
406
|
+
const now = new Date();
|
|
407
|
+
const claimed = await tx
|
|
408
|
+
.getRepository(enrollment_1.Enrollment)
|
|
409
|
+
.update({ id: enrollment.id, status: (0, typeorm_1.In)(enrollment_1.OPEN_ENROLLMENT_STATUSES) }, { status: enrollment_1.EnrollmentStatus.COMPLETED, completedAt: now, certificateNo: (0, exports.certificateNoOf)(enrollment, (0, exports.todayIn)(domain, now)), updater: context.state.user });
|
|
410
|
+
if (!claimed.affected)
|
|
411
|
+
return await enrollmentOf(tx, domain, enrollment.id);
|
|
412
|
+
const completed = await enrollmentOf(tx, domain, enrollment.id);
|
|
413
|
+
await (0, learning_outcome_1.learningOutcomeOf)(completed.sourceKind)?.completed(completed, context);
|
|
414
|
+
await completeTodo(tx, domain, completed, context.state.user);
|
|
415
|
+
return completed;
|
|
416
|
+
}
|
|
417
|
+
/* ---------------------------------------------------------------- whom an enrolment is for */
|
|
418
|
+
/** The open and completed enrolments of the request's person, the open first and the soonest due first. */
|
|
419
|
+
async function myEnrollments(context) {
|
|
420
|
+
const { domain, user } = context.state;
|
|
421
|
+
const rows = await (0, course_service_1.learningManagerOf)(context)
|
|
422
|
+
.getRepository(enrollment_1.Enrollment)
|
|
423
|
+
.find({ where: { domain: { id: domain.id }, user: { id: user.id }, status: (0, typeorm_1.In)([...enrollment_1.OPEN_ENROLLMENT_STATUSES, enrollment_1.EnrollmentStatus.COMPLETED]) } });
|
|
424
|
+
const rank = (one) => (isOpen(one.status) ? 0 : 1);
|
|
425
|
+
return rows.sort((a, b) => rank(a) - rank(b) || String(a.dueOn ?? '9999').localeCompare(String(b.dueOn ?? '9999')) || +new Date(b.createdAt) - +new Date(a.createdAt));
|
|
426
|
+
}
|
|
427
|
+
//# sourceMappingURL=enrollment-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enrollment-service.js","sourceRoot":"","sources":["../../../server/service/enrollment/enrollment-service.ts"],"names":[],"mappings":";;;AAqGA,wBA0BC;AAMD,4BAMC;AAcD,4CAYC;AAMD,gCAUC;AAID,oCAIC;AAGD,wCAIC;AAGD,wCAGC;AAED,oCAEC;AAGD,gCAiBC;AAkCD,gCAiCC;AAGD,sDAOC;AAUD,gCAaC;AAgBD,4CAcC;AAaD,8CAkBC;AAYD,sCAYC;AAKD,sCAOC;AAvaD;;;;;GAKG;AACH,qCAAmD;AAEnD,yDAAgD;AAChD,+DAAsH;AACtH,6CAA4C;AAC5C,qEAAoE;AACpE,iDAA2E;AAC3E,uDAAmG;AAEnG,iDAA2D;AAE3D,+DAA0D;AAC1D,uDAAkE;AAClE,6DAAwD;AACxD,6DAAgH;AAChH,6CAAqF;AACrF,yDAAsD;AACtD,qDAA4G;AAC5G,iDAA4C;AAC5C,mDAA8C;AAQjC,QAAA,kBAAkB,GAAG,iBAAiB,CAAA;AAEnD,qEAAqE;AAC9D,MAAM,iBAAiB,GAAG,CAAC,YAAoB,EAAE,EAAE,CAAC,oBAAoB,YAAY,EAAE,CAAA;AAAhF,QAAA,iBAAiB,qBAA+D;AAEtF,MAAM,OAAO,GAAG,CAAC,MAAoC,EAAE,MAAY,IAAI,IAAI,EAAE,EAAE,EAAE,CAAC,IAAA,mBAAW,EAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAA;AAA9G,QAAA,OAAO,WAAuG;AAE3H,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,IAAI,eAAO,C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AE,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAA,YAAE,EAAC,CAAC,GAAG,qCAAwB,EAAE,6BAAgB,CAAC,SAAS,CAAC,CAAC,EAAS,EAAE,CAAC,CAAA;IACtJ,MAAM,IAAI,GAAG,CAAC,GAAe,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9D,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,SAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,SAAU,CAAC,CAAC,CAAA;AAC1K,CAAC","sourcesContent":["/*\n * What the doors of enrolments do with the database (ADR-0194 decisions 5-8): enrolling people for whoever asks and\n * withdrawing them, the to-do of each, the time the server counts from ticks, the quiz the server scores, the\n * acknowledgement, and completing an enrolment with its evidence in the same transaction as the handler of whoever\n * asked. Nothing here deletes an enrolment or its progress.\n */\nimport { EntityManager, In, IsNull } from 'typeorm'\n\nimport { User } from '@things-factory/auth-base'\nimport { audienceTargetRefusal, audienceUserIds, departmentTreeOf, domainRolesOf } from '@things-factory/organization'\nimport { logger } from '@things-factory/env'\nimport { translatorFor } from '@things-factory/i18n-base/translator'\nimport { calendarDay, getRepository, Refusal } from '@things-factory/shell'\nimport { abort, Activity, ActivityThread, assign, complete, issue } from '@things-factory/worklist'\n\nimport { LEARNING_COURSE_ACTIVITY } from '../../activities'\nimport { Course } from '../course/course'\nimport { CourseQuestion } from '../course/course-question'\nimport { CourseUnit, CourseUnitKind } from '../course/course-unit'\nimport { CourseVersion } from '../course/course-version'\nimport { courseOf, learningManagerOf, publishedVersionOf, questionsOf, unitsOf } from '../course/course-service'\nimport { Enrollment, EnrollmentStatus, OPEN_ENROLLMENT_STATUSES } from './enrollment'\nimport { learningOutcomeOf } from './learning-outcome'\nimport { counts, drawQuestions, missingOf, Missing, scoreOf, tickVerdict, unitDone } from './progress-rules'\nimport { QuizAttempt } from './quiz-attempt'\nimport { UnitProgress } from './unit-progress'\n\n/** Who asked for an enrolment - a module's kind of record and the record. A manager's own is `learning.direct`. */\nexport interface LearningSource {\n kind: string\n id?: string | null\n}\n\nexport const DIRECT_SOURCE_KIND = 'learning.direct'\n\n/** The learner's screen of one enrolment - where the to-do leads. */\nexport const learningAddressOf = (enrollmentId: string) => `learning-view?id=${enrollmentId}`\n\nexport const todayIn = (domain: { timezone?: string | null }, now: Date = new Date()) => calendarDay(domain?.timezone, now)\n\nconst notFound = () => new Refusal('learning-not-found', {}, 'the record was not found. reload and try again.')\nconst isOpen = (status: string) => (OPEN_ENROLLMENT_STATUSES as string[]).includes(status)\n\n/* ---------------------------------------------------------------- the to-do (decision 5) */\n\n/** The to-do is issued as its own assignee: nobody else hands it out. worklist speaks its refusals through `t`. */\nfunction todoContextOf(tx: EntityManager, domain: any, user: User) {\n const t = translatorFor(user.locale || 'ko')\n return { state: { domain, user, tx }, t: (key: string, options?: any) => t(key, options) } as any\n}\n\n/** Hands out 「<과정> 수강」 to the person, with the due day - nothing where the domain has not installed the to-do. */\nasync function issueTodo(tx: EntityManager, domain: any, enrollment: Enrollment, course: Course, person: User): Promise<string | null> {\n const activity = await tx.getRepository(Activity).findOne({ where: { domain: { id: domain.id }, name: LEARNING_COURSE_ACTIVITY } as any })\n if (!activity) {\n logger.warn(`[learning] ${domain.subdomain}: the activity \"${LEARNING_COURSE_ACTIVITY}\" is not installed - \"${course.name}\" not handed out`)\n return null\n }\n const t = translatorFor(person.locale || 'ko')\n const name = t('text.learning-todo-name', { course: course.name })\n const headline = enrollment.dueOn ? t('text.learning-todo-headline', { dueOn: enrollment.dueOn }) : t('text.learning-todo-headline-no-due')\n const dueAt = enrollment.dueOn ? dueAtOf(enrollment.dueOn, domain.timezone) : undefined\n const context = todoContextOf(tx, domain, person)\n const input = { enrollmentId: enrollment.id, headline, address: learningAddressOf(enrollment.id) }\n const instance = await issue({ name, description: headline, activityId: activity.id, input, assignees: [], threadsMin: 0, dueAt } as any, context)\n await assign({ id: instance.id, assignees: [person.email], dueAt, reason: name }, context)\n return instance.id\n}\n\n/** The end of the due day in the domain's time zone. */\nfunction dueAtOf(dueOn: string, timezone?: string | null): Date {\n const end = new Date(`${dueOn}T23:59:59Z`)\n const zone = timezone || 'UTC'\n const asLocal = new Date(end.toLocaleString('en-US', { timeZone: zone }))\n const asUtc = new Date(end.toLocaleString('en-US', { timeZone: 'UTC' }))\n return new Date(end.getTime() - (asLocal.getTime() - asUtc.getTime()))\n}\n\nasync function todoOpen(tx: EntityManager, instanceId: string): Promise<boolean> {\n return (await tx.getRepository(ActivityThread).count({ where: { activityInstance: { id: instanceId }, state: In(['assigned', 'started', 'unassigned']) } as any })) > 0\n}\n\n/** Ends the to-do as done once the course is completed. */\nasync function completeTodo(tx: EntityManager, domain: any, enrollment: Enrollment, by: User): Promise<void> {\n if (!enrollment.todoInstanceId || !(await todoOpen(tx, enrollment.todoInstanceId))) return\n await complete({ id: enrollment.todoInstanceId, reason: 'course completed' }, todoContextOf(tx, domain, by))\n}\n\n/** Aborts the to-do of an enrolment withdrawn or cancelled. */\nasync function abortTodo(tx: EntityManager, domain: any, enrollment: Enrollment, by: User, reason: string): Promise<void> {\n if (!enrollment.todoInstanceId || !(await todoOpen(tx, enrollment.todoInstanceId))) return\n await abort({ id: enrollment.todoInstanceId, reason } as any, todoContextOf(tx, domain, by))\n}\n\n/* ---------------------------------------------------------------- enrolling and withdrawing (decision 7) */\n\n/**\n * Enrols people in a course for whoever asks (`source`), to be completed by `dueOn` - the server function a using module\n * calls with the people it chose. One open enrolment per person, course and source: a person who has one is left with\n * it. Each new enrolment hands out its to-do. Answers the open enrolments of everyone given.\n */\nexport async function enroll(source: LearningSource, userIds: string[], courseId: string, dueOn: string | null | undefined, context: any): Promise<Enrollment[]> {\n const { domain, user, tx } = context.state\n if (!source?.kind) throw new Refusal('learning-source-required', {}, 'an enrolment names who asked for it')\n if (dueOn && !/^\\d{4}-\\d{2}-\\d{2}$/.test(dueOn)) throw new Refusal('learning-due-invalid', {}, 'the due day is YYYY-MM-DD')\n const course = await courseOf(tx, domain, courseId)\n if (!(await publishedVersionOf(tx, domain, course.id))) throw new Refusal('learning-course-not-published', { course: course.name }, `${course.name} has no published version`)\n const ids = [...new Set(userIds)].filter(Boolean)\n if (!ids.length) return []\n const people = await (tx as EntityManager).getRepository(User).find({ where: { id: In(ids) }, relations: ['domains'] })\n const sourceId = source.id ?? ''\n const repository = (tx as EntityManager).getRepository(Enrollment)\n const out: Enrollment[] = []\n for (const id of ids) {\n const person = people.find(one => one.id === id)\n if (!person || !(person.domains ?? []).some(one => one.id === domain.id)) throw new Refusal('learning-learner-unknown', {}, 'a learner must be a user of this domain')\n const open = await repository.findOne({ where: { domain: { id: domain.id }, user: { id }, course: { id: course.id }, sourceKind: source.kind, sourceId, status: In(OPEN_ENROLLMENT_STATUSES) } as any })\n if (open) {\n out.push(open)\n continue\n }\n const saved = await repository.save({ domain, user: person, course, dueOn: dueOn || null, sourceKind: source.kind, sourceId, status: EnrollmentStatus.ASSIGNED, learnedSeconds: 0, attempts: 0, creator: user, updater: user } as any)\n const todo = await issueTodo(tx, domain, saved, course, person)\n if (todo) await repository.update(saved.id, { todoInstanceId: todo } as any)\n out.push((await repository.findOneBy({ id: saved.id }))!)\n }\n return out\n}\n\n/**\n * Withdraws the open enrolments a source asked for - the record they were for was taken back. Each is cancelled with\n * the reason and its to-do aborted; completed ones stay. Answers how many were withdrawn.\n */\nexport async function withdraw(source: LearningSource, reason: string, context: any): Promise<number> {\n const { domain, user, tx } = context.state\n const rows = await (tx as EntityManager).getRepository(Enrollment).find({ where: { domain: { id: domain.id }, sourceKind: source.kind, sourceId: source.id ?? '', status: In(OPEN_ENROLLMENT_STATUSES) } as any })\n let count = 0\n for (const row of rows) if (await cancelOpen(tx, domain, row, user, reason)) count++\n return count\n}\n\n/** Cancels an open enrolment - claimed by an update only an open one matches, so a completion at the same time wins once. */\nasync function cancelOpen(tx: EntityManager, domain: any, row: Enrollment, by: User, reason: string): Promise<boolean> {\n const claimed = await tx.getRepository(Enrollment).update({ id: row.id, status: In(OPEN_ENROLLMENT_STATUSES) } as any, { status: EnrollmentStatus.CANCELLED, cancelledAt: new Date(), cancelReason: reason, updater: by } as any)\n if (!claimed.affected) return false\n await abortTodo(tx, domain, row, by, reason)\n return true\n}\n\n/**\n * A manager cancels an enrolment with a reason (decision 8). An open one is withdrawn; a completed one stays on record as\n * cancelled - never deleted - and whoever asked for it is told in the same transaction.\n */\nexport async function cancelEnrollment(id: string, reason: string, context: any): Promise<Enrollment> {\n const { domain, user, tx } = context.state\n if (!reason?.trim()) throw new Refusal('learning-cancel-reason-required', {}, 'say why it is cancelled')\n const row = await enrollmentOf(tx, domain, id)\n if (isOpen(row.status)) {\n if (!(await cancelOpen(tx, domain, row, user, reason.trim()))) throw new Refusal('learning-enrollment-moved', {}, 'the enrolment changed meanwhile - reload and try again')\n } else if (row.status === EnrollmentStatus.COMPLETED) {\n const claimed = await tx.getRepository(Enrollment).update({ id: row.id, status: EnrollmentStatus.COMPLETED } as any, { status: EnrollmentStatus.CANCELLED, cancelledAt: new Date(), cancelReason: reason.trim(), updater: user } as any)\n if (!claimed.affected) throw new Refusal('learning-enrollment-moved', {}, 'the enrolment changed meanwhile - reload and try again')\n await learningOutcomeOf(row.sourceKind)?.cancelled?.((await enrollmentOf(tx, domain, id))!, reason.trim(), context)\n } else throw new Refusal('learning-enrollment-cancelled', {}, 'the enrolment is cancelled already')\n return await enrollmentOf(tx, domain, id)\n}\n\n/**\n * The people an audience names now - the domain, departments with those under them, roles and people, by organization's\n * one rule (ADR-0163). Each target must be of this domain.\n */\nexport async function learnersOf(audiences: { scope: string; targetId: string; targetName?: string }[], context: any): Promise<string[]> {\n const { domain, tx } = context.state\n if (!audiences?.length) throw new Refusal('learning-audience-required', {}, 'pick who takes the course')\n const departmentIds = [...(await departmentTreeOf(domain, tx)).keys()]\n const roleIds = (await domainRolesOf(domain, undefined, tx)).map(one => one.id)\n for (const target of audiences) {\n const why = audienceTargetRefusal(target as any, { domainId: domain.id, departmentIds, roleIds })\n if (why) throw new Refusal('learning-audience-invalid', { target: target.targetName ?? target.targetId }, `${target.targetName ?? target.targetId} is not of this domain (${why})`)\n }\n return await audienceUserIds(domain, audiences as any, tx)\n}\n\n/* ---------------------------------------------------------------- reading */\n\nexport async function enrollmentOf(tx: EntityManager, domain: { id: string }, id: string): Promise<Enrollment> {\n const row = id && /^[0-9a-f-]{36}$/i.test(id) ? await tx.getRepository(Enrollment).findOne({ where: { id, domain: { id: domain.id } } as any }) : null\n if (!row) throw notFound()\n return row\n}\n\n/** The request's own enrolment - one answer for \"none\" and \"not yours\". */\nexport async function myEnrollmentOf(context: any, id: string, tx: EntityManager = learningManagerOf(context)): Promise<Enrollment> {\n const row = await enrollmentOf(tx, context.state.domain, id)\n if (row.userId !== context.state.user.id) throw notFound()\n return row\n}\n\n/** The version an enrolment shows: its own once started, the published one before. */\nexport async function shownVersionOf(tx: EntityManager, domain: { id: string }, enrollment: Enrollment): Promise<CourseVersion | null> {\n if (enrollment.versionId) return await tx.getRepository(CourseVersion).findOne({ where: { id: enrollment.versionId } as any, withDeleted: true })\n return await publishedVersionOf(tx, domain, enrollment.courseId!)\n}\n\nexport async function progressesOf(tx: EntityManager, enrollmentId: string): Promise<UnitProgress[]> {\n return await tx.getRepository(UnitProgress).find({ where: { enrollment: { id: enrollmentId } } as any })\n}\n\n/** What still stands between an enrolment and its completion - nothing for a completed one. */\nexport async function missingFor(tx: EntityManager, domain: { id: string }, enrollment: Enrollment): Promise<Missing[]> {\n if (enrollment.status === EnrollmentStatus.COMPLETED) return []\n const version = await shownVersionOf(tx, domain, enrollment)\n if (!version) return ['units']\n const units = (await unitsOf(tx, version.id)).filter(counts)\n const progress = await progressesOf(tx, enrollment.id)\n const questions = version.passScore != null ? await tx.getRepository(CourseQuestion).count({ where: { version: { id: version.id } } as any }) : 0\n return missingOf({\n units: units.length,\n unitsDone: units.filter(unit => progress.some(one => one.unitId === unit.id && one.doneAt)).length,\n learnedSeconds: enrollment.learnedSeconds,\n minSeconds: version.minSeconds ?? 0,\n quiz: version.passScore != null && questions > 0,\n passed: enrollment.score != null && enrollment.score >= (version.passScore ?? 101),\n acknowledgement: !!version.acknowledgement,\n acknowledged: !!enrollment.acknowledgedAt\n })\n}\n\n/* ---------------------------------------------------------------- learning (decision 6) */\n\n/** The enrolment, started if it was not: its version fixed to the one published now, in progress from now on. */\nasync function started(tx: EntityManager, domain: any, enrollment: Enrollment, user: User): Promise<Enrollment> {\n if (enrollment.status === EnrollmentStatus.CANCELLED) throw new Refusal('learning-enrollment-cancelled', {}, 'the enrolment is cancelled')\n if (enrollment.versionId) {\n if (enrollment.status === EnrollmentStatus.ASSIGNED) await tx.getRepository(Enrollment).update({ id: enrollment.id, status: EnrollmentStatus.ASSIGNED } as any, { status: EnrollmentStatus.IN_PROGRESS, startedAt: new Date() } as any)\n return await enrollmentOf(tx, domain, enrollment.id)\n }\n const version = await publishedVersionOf(tx, domain, enrollment.courseId!)\n if (!version) throw new Refusal('learning-course-not-published', {}, 'the course has no published version')\n await tx.getRepository(Enrollment).update({ id: enrollment.id, status: In(OPEN_ENROLLMENT_STATUSES) } as any, { version, status: EnrollmentStatus.IN_PROGRESS, startedAt: enrollment.startedAt ?? new Date(), updater: user } as any)\n return await enrollmentOf(tx, domain, enrollment.id)\n}\n\nasync function unitOfVersion(tx: EntityManager, version: { id: string }, unitId: string): Promise<CourseUnit> {\n const unit = await tx.getRepository(CourseUnit).findOne({ where: { id: unitId, version: { id: version.id } } as any })\n if (!unit) throw notFound()\n return unit\n}\n\nexport interface TickResult {\n enrollment: Enrollment\n progress: UnitProgress\n}\n\n/**\n * One tick of the learner's screen on a unit (decision 6): the server adds the gap since the unit's last tick, at most\n * 15 seconds and at most what the screen says, and refuses a video position ahead of what was watched. A total the\n * screen sends is never taken. A unit that reaches its condition is done, and the enrolment is completed when nothing is\n * missing any more.\n */\nexport async function recordTick(enrollmentId: string, unitId: string, seconds: number, position: number, context: any, now: Date = new Date()): Promise<TickResult> {\n const { domain, user, tx } = context.state\n let enrollment = await myEnrollmentOf(context, enrollmentId, tx)\n enrollment = await started(tx, domain, enrollment, user)\n const unit = await unitOfVersion(tx, { id: enrollment.versionId! }, unitId)\n if (unit.kind === CourseUnitKind.LINK) throw new Refusal('learning-link-not-counted', {}, 'a link is not counted')\n const repository = (tx as EntityManager).getRepository(UnitProgress)\n const progress =\n (await repository.findOne({ where: { enrollment: { id: enrollment.id }, unit: { id: unit.id } } as any })) ??\n (await repository.save({ domain, enrollment, unit, learnedSeconds: 0, watchedSeconds: 0, positionSeconds: 0, pagesSeen: 0, pagesRead: 0, pageSeconds: 0, pageAt: 0, creator: user, updater: user } as any))\n if (enrollment.status === EnrollmentStatus.COMPLETED) return { enrollment, progress }\n\n const verdict = tickVerdict(progress, { seconds, position }, now, unit)\n if ('refusal' in verdict) {\n if (verdict.refusal === 'page-ahead') throw new Refusal('learning-page-ahead', { allowed: verdict.allowed }, `a page cannot be ahead of the one after the last read (${verdict.allowed})`)\n throw new Refusal('learning-position-ahead', { allowed: verdict.allowed }, `the video cannot be ahead of what was watched (${verdict.allowed} s)`)\n }\n progress.learnedSeconds += verdict.add\n progress.watchedSeconds = verdict.watchedSeconds\n progress.positionSeconds = verdict.positionSeconds\n progress.pagesSeen = verdict.pagesSeen\n progress.pagesRead = verdict.pagesRead\n progress.pageSeconds = verdict.pageSeconds\n progress.pageAt = verdict.pageAt\n progress.lastTickAt = now\n if (!progress.doneAt && unitDone(unit, progress)) progress.doneAt = now\n progress.updater = user\n await repository.save(progress)\n if (verdict.add) await tx.getRepository(Enrollment).increment({ id: enrollment.id } as any, 'learnedSeconds', verdict.add)\n /* Where the learner was - the course opens on this unit again (2026-11-08). */\n if (enrollment.lastUnitId !== unit.id) await tx.getRepository(Enrollment).update({ id: enrollment.id } as any, { lastUnitId: unit.id } as any)\n enrollment = await completeIfMet(tx, domain, await enrollmentOf(tx, domain, enrollment.id), context)\n return { enrollment, progress }\n}\n\n/** The learner confirms the version's acknowledgement - recorded once, when they did. */\nexport async function acknowledgeEnrollment(enrollmentId: string, context: any): Promise<Enrollment> {\n const { domain, user, tx } = context.state\n let enrollment = await started(tx, domain, await myEnrollmentOf(context, enrollmentId, tx), user)\n const version = await shownVersionOf(tx, domain, enrollment)\n if (!version?.acknowledgement) throw new Refusal('learning-no-acknowledgement', {}, 'the course asks for no acknowledgement')\n if (!enrollment.acknowledgedAt) await tx.getRepository(Enrollment).update({ id: enrollment.id } as any, { acknowledgedAt: new Date(), updater: user } as any)\n return await completeIfMet(tx, domain, await enrollmentOf(tx, domain, enrollment.id), context)\n}\n\n/* ---------------------------------------------------------------- the quiz (decision 4) */\n\nexport interface DrawnForLearner {\n attempt: QuizAttempt\n questions: { id: string; kind: string; text: string; choices: { id: string; text: string }[] }[]\n}\n\n/** The questions of an attempt as the learner is drawn them - the choices in the order shown, never whether one is right. */\nexport function forLearner(attempt: QuizAttempt, questions: CourseQuestion[]): DrawnForLearner {\n return {\n attempt,\n questions: attempt.drawn.map(drawn => {\n const question = questions.find(one => one.id === drawn.questionId)!\n return {\n id: question.id,\n kind: question.kind,\n text: question.text,\n choices: drawn.choiceIds.map(id => question.choices.find(one => one.id === id)!).map(one => ({ id: one.id, text: one.text }))\n }\n })\n }\n}\n\n/**\n * Starts an attempt at the quiz: the questions drawn and shuffled, their choices shuffled. An attempt not sent yet is\n * answered again; the version's limit on attempts holds.\n */\n/**\n * Holds the enrolment for the rest of the request's transaction - an update takes its row lock on every driver, so two\n * attempts of one enrolment are started, counted and sent one after the other. Two starts at once made two unsent\n * attempts, and a limit of one let both be sent (2026-11-08).\n */\nasync function holdEnrollment(tx: EntityManager, domain: any, enrollment: Enrollment, user: User): Promise<Enrollment> {\n await tx.getRepository(Enrollment).update({ id: enrollment.id } as any, { updater: user } as any)\n return await enrollmentOf(tx, domain, enrollment.id)\n}\n\nexport async function startQuizAttempt(enrollmentId: string, context: any): Promise<DrawnForLearner> {\n const { domain, user, tx } = context.state\n const held = await holdEnrollment(tx, domain, await myEnrollmentOf(context, enrollmentId, tx), user)\n const enrollment = await started(tx, domain, held, user)\n if (enrollment.status === EnrollmentStatus.COMPLETED) throw new Refusal('learning-enrollment-completed', {}, 'the course is completed')\n const version = (await shownVersionOf(tx, domain, enrollment))!\n const questions = await questionsOf(tx, version.id)\n if (version.passScore == null || !questions.length) throw new Refusal('learning-no-quiz', {}, 'the course has no quiz')\n const repository = (tx as EntityManager).getRepository(QuizAttempt)\n const pending = await repository.findOne({ where: { enrollment: { id: enrollment.id }, submittedAt: IsNull() } as any })\n if (pending) return forLearner(pending, questions)\n if (version.attemptLimit != null && enrollment.attempts >= version.attemptLimit) throw new Refusal('learning-attempts-used', { limit: version.attemptLimit }, `all ${version.attemptLimit} attempts are used`)\n const attempt = await repository.save({ domain, enrollment, drawn: drawQuestions(questions, version.questionCount), creator: user, updater: user } as any)\n return forLearner(attempt, questions)\n}\n\nexport interface QuizResult {\n enrollment: Enrollment\n score: number\n passed: boolean\n attemptsLeft: number | null\n}\n\n/**\n * Scores an attempt's answers on the server against what it drew (decision 4) - only the score and whether it passed go\n * back, never the right answers. The best score stays on the enrolment; passing may complete it.\n */\nexport async function submitQuizAttempt(attemptId: string, answers: Record<string, string[]>, context: any): Promise<QuizResult> {\n const { domain, user, tx } = context.state\n const attempt = await (tx as EntityManager).getRepository(QuizAttempt).findOne({ where: { id: attemptId, domain: { id: domain.id } } as any })\n if (!attempt) throw notFound()\n const enrollment = await holdEnrollment(tx, domain, await myEnrollmentOf(context, attempt.enrollmentId!, tx), user)\n const version = (await shownVersionOf(tx, domain, enrollment))!\n if (version.attemptLimit != null && enrollment.attempts >= version.attemptLimit) throw new Refusal('learning-attempts-used', { limit: version.attemptLimit }, `all ${version.attemptLimit} attempts are used`)\n const questions = await questionsOf(tx, version.id)\n const drawn = attempt.drawn.map(one => questions.find(question => question.id === one.questionId)).filter(Boolean) as CourseQuestion[]\n const kept: Record<string, string[]> = Object.fromEntries(drawn.map(question => [question.id, (answers?.[question.id] ?? []).map(String)]))\n const score = scoreOf(drawn, kept)\n const passed = score >= (version.passScore ?? 101)\n const claimed = await tx.getRepository(QuizAttempt).update({ id: attempt.id, submittedAt: IsNull() } as any, { answers: kept, score, passed, submittedAt: new Date(), updater: user } as any)\n if (!claimed.affected) throw new Refusal('learning-attempt-sent', {}, 'the attempt was sent already')\n await tx.getRepository(Enrollment).increment({ id: enrollment.id } as any, 'attempts', 1)\n await tx.getRepository(Enrollment).update({ id: enrollment.id } as any, { score: Math.max(enrollment.score ?? 0, score), updater: user } as any)\n const after = await completeIfMet(tx, domain, await enrollmentOf(tx, domain, enrollment.id), context)\n return { enrollment: after, score, passed, attemptsLeft: version.attemptLimit != null ? Math.max(0, version.attemptLimit - after.attempts) : null }\n}\n\n/* ---------------------------------------------------------------- completing (decision 8) */\n\n/** A certificate number: the day completed and the enrolment's own id - one per completion, never reused. */\nexport const certificateNoOf = (enrollment: { id: string }, day: string) => `LMS-${day.replace(/-/g, '')}-${enrollment.id.replace(/-/g, '').slice(0, 8).toUpperCase()}`\n\n/**\n * Completes an open enrolment when nothing is missing - every unit done, the least time, the quiz passed, the\n * acknowledgement confirmed. The evidence stays on it; whoever asked for it is told in this same transaction (a handler\n * that fails takes the completion back), and the to-do ends as done.\n */\nexport async function completeIfMet(tx: EntityManager, domain: any, enrollment: Enrollment, context: any): Promise<Enrollment> {\n if (!isOpen(enrollment.status) || !enrollment.versionId) return enrollment\n if ((await missingFor(tx, domain, enrollment)).length) return enrollment\n const now = new Date()\n const claimed = await tx\n .getRepository(Enrollment)\n .update({ id: enrollment.id, status: In(OPEN_ENROLLMENT_STATUSES) } as any, { status: EnrollmentStatus.COMPLETED, completedAt: now, certificateNo: certificateNoOf(enrollment, todayIn(domain, now)), updater: context.state.user } as any)\n if (!claimed.affected) return await enrollmentOf(tx, domain, enrollment.id)\n const completed = await enrollmentOf(tx, domain, enrollment.id)\n await learningOutcomeOf(completed.sourceKind)?.completed(completed, context)\n await completeTodo(tx, domain, completed, context.state.user)\n return completed\n}\n\n/* ---------------------------------------------------------------- whom an enrolment is for */\n\n/** The open and completed enrolments of the request's person, the open first and the soonest due first. */\nexport async function myEnrollments(context: any): Promise<Enrollment[]> {\n const { domain, user } = context.state\n const rows = await learningManagerOf(context)\n .getRepository(Enrollment)\n .find({ where: { domain: { id: domain.id }, user: { id: user.id }, status: In([...OPEN_ENROLLMENT_STATUSES, EnrollmentStatus.COMPLETED]) } as any })\n const rank = (one: Enrollment) => (isOpen(one.status) ? 0 : 1)\n return rows.sort((a, b) => rank(a) - rank(b) || String(a.dueOn ?? '9999').localeCompare(String(b.dueOn ?? '9999')) || +new Date(b.createdAt!) - +new Date(a.createdAt!))\n}\n\nexport { isOpen }\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { EntityManager, SelectQueryBuilder } from 'typeorm';
|
|
2
|
+
import { User } from '@things-factory/auth-base';
|
|
3
|
+
import { ListParam, ListValueCount } from '@things-factory/shell';
|
|
4
|
+
import { Course } from '../course/course';
|
|
5
|
+
import { Enrollment } from './enrollment';
|
|
6
|
+
export interface StatusRow {
|
|
7
|
+
enrollment: Enrollment;
|
|
8
|
+
user: User | null;
|
|
9
|
+
course: Course | null;
|
|
10
|
+
departmentName: string | null;
|
|
11
|
+
/** The status as it reads today - OVERDUE for an open one past its due day. */
|
|
12
|
+
state: string;
|
|
13
|
+
units: number;
|
|
14
|
+
unitsDone: number;
|
|
15
|
+
versionNumber: number | null;
|
|
16
|
+
}
|
|
17
|
+
/** The rows of the enrolments given - each with its person, course, department, state today and units done. */
|
|
18
|
+
export declare function rowsOf(tx: EntityManager, domain: any, enrollments: Enrollment[]): Promise<StatusRow[]>;
|
|
19
|
+
/** The departments the request's person heads, with those under them - none for anyone else. */
|
|
20
|
+
export declare function headedDepartmentsOf(context: any): Promise<string[]>;
|
|
21
|
+
/** An enrolment as a department head reads it - where it stands and its days, nothing of how it went. */
|
|
22
|
+
export declare function statusOnly(enrollment: Enrollment): Enrollment;
|
|
23
|
+
/** The completion register of a course - every completed enrolment, by completion day (decision 10). */
|
|
24
|
+
export declare function completionRegister(courseId: string, context: any): Promise<StatusRow[]>;
|
|
25
|
+
/** Where an enrolment stands as a list shows it - OVERDUE is an open one past its due day, read on the day. */
|
|
26
|
+
export declare const ENROLLMENT_STATES: readonly ["ASSIGNED", "IN_PROGRESS", "COMPLETED", "OVERDUE", "CANCELLED"];
|
|
27
|
+
/**
|
|
28
|
+
* Whose enrolments a request reads (decision 11): a manager everyone's; a department head the people of their
|
|
29
|
+
* departments - open and completed ones, status only; anyone else their own.
|
|
30
|
+
*/
|
|
31
|
+
export type EnrollmentReach = {
|
|
32
|
+
kind: 'all';
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'team';
|
|
35
|
+
userIds: string[];
|
|
36
|
+
} | {
|
|
37
|
+
kind: 'own';
|
|
38
|
+
userId: string;
|
|
39
|
+
};
|
|
40
|
+
/** The people of the request's departments, refused to anyone who heads none. */
|
|
41
|
+
export declare function teamReachOf(context: any): Promise<EnrollmentReach>;
|
|
42
|
+
/** The widest reach the request has - a manager's, a department head's, or their own. */
|
|
43
|
+
export declare function reachOf(context: any): Promise<EnrollmentReach>;
|
|
44
|
+
/**
|
|
45
|
+
* One page of the enrolments a list asks for, within a reach - its conditions, search, sort and page by the framework's
|
|
46
|
+
* list rule, the rows then read with their people, courses and units. A department head's rows are status only.
|
|
47
|
+
*/
|
|
48
|
+
export declare function enrollmentPage(params: ListParam, reach: EnrollmentReach, context: any, extra?: (builder: SelectQueryBuilder<Enrollment>) => void): Promise<{
|
|
49
|
+
rows: StatusRow[];
|
|
50
|
+
total: number;
|
|
51
|
+
}>;
|
|
52
|
+
/** How many enrolments stand in each state under the list's other conditions - every state, in order. */
|
|
53
|
+
export declare function enrollmentStateCounts(params: ListParam, reach: EnrollmentReach, context: any): Promise<ListValueCount[]>;
|