@things-factory/learning 0.0.0-stage → 10.1.260
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-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 +41 -0
- package/dist-client/components/learning-unit-form.js +143 -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 +62 -0
- package/dist-client/pages/learning-course-editor.js +463 -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 +88 -0
- package/dist-client/pages/learning-course-list.js.map +1 -0
- package/dist-client/pages/learning-enrollment-status.d.ts +53 -0
- package/dist-client/pages/learning-enrollment-status.js +228 -0
- package/dist-client/pages/learning-enrollment-status.js.map +1 -0
- package/dist-client/pages/learning-view.d.ts +52 -0
- package/dist-client/pages/learning-view.js +371 -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 +16 -0
- package/dist-client/utils/learning-api.js +36 -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-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 +176 -0
- package/dist-server/service/course/course-mutation.js.map +1 -0
- package/dist-server/service/course/course-query.d.ts +26 -0
- package/dist-server/service/course/course-query.js +172 -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 +49 -0
- package/dist-server/service/course/course-rules.js +89 -0
- package/dist-server/service/course/course-rules.js.map +1 -0
- package/dist-server/service/course/course-service.d.ts +71 -0
- package/dist-server/service/course/course-service.js +402 -0
- package/dist-server/service/course/course-service.js.map +1 -0
- package/dist-server/service/course/course-type.d.ts +55 -0
- package/dist-server/service/course/course-type.js +198 -0
- package/dist-server/service/course/course-type.js.map +1 -0
- package/dist-server/service/course/course-unit.d.ts +36 -0
- package/dist-server/service/course/course-unit.js +123 -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 +14 -0
- package/dist-server/service/course/index.js +24 -0
- package/dist-server/service/course/index.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 +23 -0
- package/dist-server/service/enrollment/enrollment-query.js +245 -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 +417 -0
- package/dist-server/service/enrollment/enrollment-service.js.map +1 -0
- package/dist-server/service/enrollment/enrollment-status.d.ts +40 -0
- package/dist-server/service/enrollment/enrollment-status.js +135 -0
- package/dist-server/service/enrollment/enrollment-status.js.map +1 -0
- package/dist-server/service/enrollment/enrollment-type.d.ts +95 -0
- package/dist-server/service/enrollment/enrollment-type.js +341 -0
- package/dist-server/service/enrollment/enrollment-type.js.map +1 -0
- package/dist-server/service/enrollment/enrollment.d.ts +52 -0
- package/dist-server/service/enrollment/enrollment.js +186 -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 +38 -0
- package/dist-server/service/enrollment/learning-ai.js +96 -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 +160 -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 +94 -0
- package/dist-server/service/enrollment/progress-rules.js +97 -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 +30 -0
- package/dist-server/service/enrollment/unit-progress.js +114 -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 +56 -4
- package/things-factory.config.js +14 -0
- package/translations/en.json +255 -0
- package/translations/es.json +255 -0
- package/translations/ja.json +255 -0
- package/translations/ko.json +255 -0
- package/translations/ms.json +255 -0
- package/translations/zh.json +255 -0
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enrollment-query.js","sourceRoot":"","sources":["../../../server/service/enrollment/enrollment-query.ts"],"names":[],"mappings":";;;;AAAA,+CAAkH;AAElH,yDAAgD;AAChD,iDAA+E;AAE/E,6CAAyC;AACzC,+DAA0D;AAC1D,6DAAwD;AACxD,6DAA4E;AAC5E,6CAAyC;AACzC,6DAAuH;AACvH,2DAA2G;AAC3G,uDAA4J;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6CAAlB,uBAAU;;4CAEnC;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,8BAAY,CAAC,EAAE,EAAE,WAAW,EAAE,yEAAyE,EAAE,CAAC;IACrH,mBAAA,IAAA,mBAAI,GAAE,CAAA;IAA0B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAAlB,uBAAU;;4CAOzC;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,WAAW,EAAE,2EAA2E,EAAE,CAAC;IAC/G,mBAAA,IAAA,mBAAI,GAAE,CAAA;IAA0B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAAlB,uBAAU;;8CAG3C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,4DAA4D,EAAE,CAAC;IACtG,mBAAA,IAAA,mBAAI,GAAE,CAAA;IAA0B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAAlB,uBAAU;;mDAIhD;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,EAAE,EAAE,WAAW,EAAE,yDAAyD,EAAE,CAAC;IACvF,mBAAA,IAAA,mBAAI,GAAE,CAAA;IAA0B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAAlB,uBAAU;;+CAM5C;0BAvGU,eAAe;IAF3B,IAAA,uBAAQ,EAAC,uBAAU,CAAC;IACpB,IAAA,4BAAa,EAAC,qBAAa,CAAC;GAChB,eAAe,CAwG3B","sourcesContent":["import { Arg, Args, Ctx, Directive, FieldResolver, Int, Query, Resolver, Root, UseMiddleware } from 'type-graphql'\n\nimport { User } from '@things-factory/auth-base'\nimport { getRepository, ListParam, SpeakRefusals } from '@things-factory/shell'\n\nimport { Course } from '../course/course'\nimport { CourseQuestion } from '../course/course-question'\nimport { CourseVersion } from '../course/course-version'\nimport { holds, learningManagerOf, unitsOf } from '../course/course-service'\nimport { Enrollment } from './enrollment'\nimport { missingFor, myEnrollmentOf, myEnrollments, progressesOf, shownVersionOf, todayIn } from './enrollment-service'\nimport { completionRegister, enrollmentStatus, StatusRow, teamEnrollmentStatus } from './enrollment-status'\nimport { EnrollmentStatusFilter, EnrollmentStatusList, EnrollmentStatusRow, LearningContent, LearningEnrollmentList, LearningUnit } from './enrollment-type'\nimport { courseContent, readableEnrollments } from './learning-ai'\nimport { counts, overdue } from './progress-rules'\n\n\nconst rowOut = (row: StatusRow): EnrollmentStatusRow => ({ id: row.enrollment.id, ...row })\n\nfunction listOf(rows: StatusRow[]): EnrollmentStatusList {\n const live = rows.filter(one => one.state !== 'CANCELLED')\n return {\n items: rows.map(rowOut),\n summary: {\n total: live.length,\n assigned: live.filter(one => one.enrollment.status === 'ASSIGNED').length,\n inProgress: live.filter(one => one.enrollment.status === 'IN_PROGRESS').length,\n completed: live.filter(one => one.state === 'COMPLETED').length,\n overdue: live.filter(one => one.state === 'OVERDUE').length\n }\n }\n}\n\n/** Whether the request reads how an enrolment went - its learner or a manager. */\nasync function readsInside(enrollment: Enrollment, context: any): Promise<boolean> {\n return enrollment.userId === context.state.user.id || (await holds(context, 'course', 'query'))\n}\n\n/*\n * The reads of enrolments (ADR-0194 decisions 5-11): one's own (`learning` query, the task `learning.taking`); every\n * enrolment and the completion register for a manager (`course` query); a department head's people, status only.\n */\n@Resolver(Enrollment)\n@UseMiddleware(SpeakRefusals)\nexport class EnrollmentQuery {\n @Directive('@privilege(category: \"learning\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => [Enrollment], { description: \"The request's own enrolments - open ones first, the soonest due first, then the completed.\" })\n async myEnrollments(@Ctx() context: ResolverContext): Promise<Enrollment[]> {\n return await myEnrollments(context)\n }\n\n @Directive('@privilege(category: \"learning\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => Enrollment, { description: \"One of the request's own enrolments.\" })\n async myEnrollment(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Enrollment> {\n return await myEnrollmentOf(context, id)\n }\n\n @Directive('@privilege(category: \"learning\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => EnrollmentStatusList, { description: \"Where the people of the request's departments stand - for a department head, status and days only.\" })\n async teamEnrollmentStatus(@Arg('filter', type => EnrollmentStatusFilter, { nullable: true }) filter: EnrollmentStatusFilter, @Ctx() context: ResolverContext): Promise<EnrollmentStatusList> {\n return listOf(await teamEnrollmentStatus(filter ?? {}, context))\n }\n\n @Directive('@privilege(category: \"course\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => EnrollmentStatusList, { description: 'Every enrolment of a course or a source, with its progress and evidence.' })\n async enrollmentStatus(@Arg('filter', type => EnrollmentStatusFilter, { nullable: true }) filter: EnrollmentStatusFilter, @Ctx() context: ResolverContext): Promise<EnrollmentStatusList> {\n return listOf(await enrollmentStatus(filter ?? {}, context))\n }\n\n @Directive('@privilege(category: \"course\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => [EnrollmentStatusRow], { description: 'The completion register of a course - every completion by its day.' })\n async completionRegister(@Arg('courseId') courseId: string, @Ctx() context: ResolverContext): Promise<EnrollmentStatusRow[]> {\n return (await completionRegister(courseId, context)).map(rowOut)\n }\n\n @Directive('@privilege(category: \"learning\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => LearningEnrollmentList, { description: 'The enrolments the request may read - a manager every one, a department head their people (status only), anyone else their own - for the assistant (ADR-0194 decision 12).' })\n async learningEnrollments(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<LearningEnrollmentList> {\n let rows = await readableEnrollments(context)\n for (const filter of params?.filters ?? []) {\n const values = Array.isArray(filter.value) ? filter.value.map(String) : [String(filter.value)]\n if (filter.name === 'state') rows = rows.filter(row => values.includes(row.state) !== (filter.operator === 'notin' || filter.operator === 'noteq'))\n }\n const search = String(params?.search ?? params?.filters?.find(one => one.operator === 'search')?.value ?? '').replace(/%/g, '').trim()\n if (search) rows = rows.filter(row => `${row.learner} ${row.departmentName ?? ''} ${row.course}`.includes(search))\n const { page = 1, limit = 0 } = (params?.pagination ?? {}) as any\n return { items: limit > 0 ? rows.slice((page - 1) * limit, page * limit) : rows, total: rows.length }\n }\n\n @Directive('@privilege(category: \"learning\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => LearningContent, { description: \"The units of one course version for the assistant - a learner's own enrolment's (not while a quiz attempt is open), or a version for a manager (ADR-0194 decision 12).\" })\n async learningContent(@Arg('enrollmentId', { nullable: true }) enrollmentId: string, @Arg('versionId', { nullable: true }) versionId: string, @Ctx() context: ResolverContext): Promise<LearningContent> {\n return await courseContent({ enrollmentId, versionId }, context)\n }\n\n /* ---------------------------------------------------------------- fields */\n\n @FieldResolver(type => Course, { nullable: true, description: 'The course.' })\n async course(@Root() enrollment: Enrollment): Promise<Course | null> {\n return enrollment.courseId ? await getRepository(Course).findOneBy({ id: enrollment.courseId }) : null\n }\n\n @FieldResolver(type => User, { nullable: true, description: 'Who takes it.' })\n async user(@Root() enrollment: Enrollment): Promise<User | null> {\n return enrollment.userId ? await getRepository(User).findOneBy({ id: enrollment.userId }) : null\n }\n\n @FieldResolver(type => CourseVersion, { nullable: true, description: 'The version it shows - its own once started, the published one before.' })\n async version(@Root() enrollment: Enrollment, @Ctx() context: ResolverContext): Promise<CourseVersion | null> {\n return await shownVersionOf(learningManagerOf(context), context.state.domain, enrollment)\n }\n\n @FieldResolver(type => String, { description: 'Where it stands today - OVERDUE for an open one past its due day.' })\n state(@Root() enrollment: Enrollment, @Ctx() context: ResolverContext): string {\n return overdue(enrollment, todayIn(context.state.domain)) ? 'OVERDUE' : enrollment.status\n }\n\n @FieldResolver(type => [LearningUnit], { description: 'Its units with how far the learner went - for its learner and managers.' })\n async units(@Root() enrollment: Enrollment, @Ctx() context: ResolverContext): Promise<LearningUnit[]> {\n if (!(await readsInside(enrollment, context))) return []\n const tx = learningManagerOf(context)\n const version = await shownVersionOf(tx, context.state.domain, enrollment)\n if (!version) return []\n const progress = await progressesOf(tx, enrollment.id)\n return (await unitsOf(tx, version.id)).map(unit => ({ unit, progress: progress.find(one => one.unitId === unit.id) ?? null, counts: counts(unit) }))\n }\n\n @FieldResolver(type => [String], { description: 'What still stands before completion - units, time, quiz, acknowledgement.' })\n async missing(@Root() enrollment: Enrollment, @Ctx() context: ResolverContext): Promise<string[]> {\n if (!(await readsInside(enrollment, context))) return []\n return await missingFor(learningManagerOf(context), context.state.domain, enrollment)\n }\n\n @FieldResolver(type => Int, { nullable: true, description: 'The quiz attempts left - no limit, or no quiz, when empty.' })\n async attemptsLeft(@Root() enrollment: Enrollment, @Ctx() context: ResolverContext): Promise<number | null> {\n if (!(await readsInside(enrollment, context))) return null\n const version = await shownVersionOf(learningManagerOf(context), context.state.domain, enrollment)\n return version?.attemptLimit != null ? Math.max(0, version.attemptLimit - (enrollment.attempts ?? 0)) : null\n }\n\n @FieldResolver(type => Int, { description: 'How many questions its quiz draws - 0 when it has none.' })\n async quizSize(@Root() enrollment: Enrollment, @Ctx() context: ResolverContext): Promise<number> {\n const tx = learningManagerOf(context)\n const version = await shownVersionOf(tx, context.state.domain, enrollment)\n if (!version || version.passScore == null) return 0\n const all = await tx.getRepository(CourseQuestion).count({ where: { version: { id: version.id } } as any })\n return version.questionCount ? Math.min(version.questionCount, all) : all\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function remindEnrollments(ids: string[], context: any): Promise<number>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remindEnrollments = remindEnrollments;
|
|
4
|
+
/*
|
|
5
|
+
* A manager reminds learners of their open enrolments (ADR-0194 decision 10) - through notification, as every notice
|
|
6
|
+
* goes: the app, a web push and a mail where the domain turned it on. Sent once the request commits.
|
|
7
|
+
*/
|
|
8
|
+
const typeorm_1 = require("typeorm");
|
|
9
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
10
|
+
const translator_1 = require("@things-factory/i18n-base/translator");
|
|
11
|
+
const notification_1 = require("@things-factory/notification");
|
|
12
|
+
const course_1 = require("../course/course");
|
|
13
|
+
const enrollment_1 = require("./enrollment");
|
|
14
|
+
const enrollment_service_1 = require("./enrollment-service");
|
|
15
|
+
async function remindEnrollments(ids, context) {
|
|
16
|
+
const { domain, tx } = context.state;
|
|
17
|
+
if (!ids?.length)
|
|
18
|
+
return 0;
|
|
19
|
+
const rows = await tx.getRepository(enrollment_1.Enrollment).find({ where: { id: (0, typeorm_1.In)(ids), domain: { id: domain.id }, status: (0, typeorm_1.In)(enrollment_1.OPEN_ENROLLMENT_STATUSES) } });
|
|
20
|
+
for (const row of rows) {
|
|
21
|
+
const user = await tx.getRepository(auth_base_1.User).findOneBy({ id: row.userId });
|
|
22
|
+
const course = await tx.getRepository(course_1.Course).findOneBy({ id: row.courseId });
|
|
23
|
+
if (!user || !course)
|
|
24
|
+
continue;
|
|
25
|
+
const address = (0, enrollment_service_1.learningAddressOf)(row.id);
|
|
26
|
+
(0, notification_1.sendNoticeWhenCommitted)(context, {
|
|
27
|
+
type: 'learning',
|
|
28
|
+
label: `learning reminded ${row.id}`,
|
|
29
|
+
receivers: [{ id: user.id, email: user.email, locale: user.locale }],
|
|
30
|
+
address,
|
|
31
|
+
link: (0, notification_1.noticeLinkOf)(context, address),
|
|
32
|
+
words: (lng) => {
|
|
33
|
+
const t = (0, translator_1.translatorFor)(lng);
|
|
34
|
+
return {
|
|
35
|
+
subject: t('text.learning-remind-subject', { course: course.name }),
|
|
36
|
+
body: row.dueOn ? t('text.learning-remind-body', { course: course.name, dueOn: row.dueOn }) : t('text.learning-remind-body-no-due', { course: course.name }),
|
|
37
|
+
action: t('text.learning-remind-action'),
|
|
38
|
+
note: t('text.learning-remind-note')
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return rows.length;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=enrollment-remind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enrollment-remind.js","sourceRoot":"","sources":["../../../server/service/enrollment/enrollment-remind.ts"],"names":[],"mappings":";;AAcA,8CA2BC;AAzCD;;;GAGG;AACH,qCAA4B;AAE5B,yDAAgD;AAChD,qEAAoE;AACpE,+DAAoF;AAEpF,6CAAyC;AACzC,6CAAmE;AACnE,6DAAwD;AAEjD,KAAK,UAAU,iBAAiB,CAAC,GAAa,EAAE,OAAY;IACjE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IACpC,IAAI,CAAC,GAAG,EAAE,MAAM;QAAE,OAAO,CAAC,CAAA;IAC1B,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,uBAAU,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,IAAA,YAAE,EAAC,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAA,YAAE,EAAC,qCAAwB,CAAC,EAAS,EAAE,CAAC,CAAA;IACxJ,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,gBAAI,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAA;QACvE,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,eAAM,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC7E,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM;YAAE,SAAQ;QAC9B,MAAM,OAAO,GAAG,IAAA,sCAAiB,EAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACzC,IAAA,sCAAuB,EAAC,OAAO,EAAE;YAC/B,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,qBAAqB,GAAG,CAAC,EAAE,EAAE;YACpC,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;YACpE,OAAO;YACP,IAAI,EAAE,IAAA,2BAAY,EAAC,OAAO,EAAE,OAAO,CAAC;YACpC,KAAK,EAAE,CAAC,GAAW,EAAE,EAAE;gBACrB,MAAM,CAAC,GAAG,IAAA,0BAAa,EAAC,GAAG,CAAC,CAAA;gBAC5B,OAAO;oBACL,OAAO,EAAE,CAAC,CAAC,8BAA8B,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;oBACnE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,2BAA2B,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kCAAkC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;oBAC5J,MAAM,EAAE,CAAC,CAAC,6BAA6B,CAAC;oBACxC,IAAI,EAAE,CAAC,CAAC,2BAA2B,CAAC;iBACrC,CAAA;YACH,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAA;AACpB,CAAC","sourcesContent":["/*\n * A manager reminds learners of their open enrolments (ADR-0194 decision 10) - through notification, as every notice\n * goes: the app, a web push and a mail where the domain turned it on. Sent once the request commits.\n */\nimport { In } from 'typeorm'\n\nimport { User } from '@things-factory/auth-base'\nimport { translatorFor } from '@things-factory/i18n-base/translator'\nimport { noticeLinkOf, sendNoticeWhenCommitted } from '@things-factory/notification'\n\nimport { Course } from '../course/course'\nimport { Enrollment, OPEN_ENROLLMENT_STATUSES } from './enrollment'\nimport { learningAddressOf } from './enrollment-service'\n\nexport async function remindEnrollments(ids: string[], context: any): Promise<number> {\n const { domain, tx } = context.state\n if (!ids?.length) return 0\n const rows = await tx.getRepository(Enrollment).find({ where: { id: In(ids), domain: { id: domain.id }, status: In(OPEN_ENROLLMENT_STATUSES) } as any })\n for (const row of rows) {\n const user = await tx.getRepository(User).findOneBy({ id: row.userId })\n const course = await tx.getRepository(Course).findOneBy({ id: row.courseId })\n if (!user || !course) continue\n const address = learningAddressOf(row.id)\n sendNoticeWhenCommitted(context, {\n type: 'learning',\n label: `learning reminded ${row.id}`,\n receivers: [{ id: user.id, email: user.email, locale: user.locale }],\n address,\n link: noticeLinkOf(context, address),\n words: (lng: string) => {\n const t = translatorFor(lng)\n return {\n subject: t('text.learning-remind-subject', { course: course.name }),\n body: row.dueOn ? t('text.learning-remind-body', { course: course.name, dueOn: row.dueOn }) : t('text.learning-remind-body-no-due', { course: course.name }),\n action: t('text.learning-remind-action'),\n note: t('text.learning-remind-note')\n }\n }\n })\n }\n return rows.length\n}\n"]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { EntityManager } from 'typeorm';
|
|
2
|
+
import { CourseQuestion } from '../course/course-question';
|
|
3
|
+
import { CourseVersion } from '../course/course-version';
|
|
4
|
+
import { Enrollment } from './enrollment';
|
|
5
|
+
import { Missing } from './progress-rules';
|
|
6
|
+
import { QuizAttempt } from './quiz-attempt';
|
|
7
|
+
import { UnitProgress } from './unit-progress';
|
|
8
|
+
/** Who asked for an enrolment - a module's kind of record and the record. A manager's own is `learning.direct`. */
|
|
9
|
+
export interface LearningSource {
|
|
10
|
+
kind: string;
|
|
11
|
+
id?: string | null;
|
|
12
|
+
}
|
|
13
|
+
export declare const DIRECT_SOURCE_KIND = "learning.direct";
|
|
14
|
+
/** The learner's screen of one enrolment - where the to-do leads. */
|
|
15
|
+
export declare const learningAddressOf: (enrollmentId: string) => string;
|
|
16
|
+
export declare const todayIn: (domain: {
|
|
17
|
+
timezone?: string | null;
|
|
18
|
+
}, now?: Date) => string;
|
|
19
|
+
declare const isOpen: (status: string) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Enrols people in a course for whoever asks (`source`), to be completed by `dueOn` - the server function a using module
|
|
22
|
+
* calls with the people it chose. One open enrolment per person, course and source: a person who has one is left with
|
|
23
|
+
* it. Each new enrolment hands out its to-do. Answers the open enrolments of everyone given.
|
|
24
|
+
*/
|
|
25
|
+
export declare function enroll(source: LearningSource, userIds: string[], courseId: string, dueOn: string | null | undefined, context: any): Promise<Enrollment[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Withdraws the open enrolments a source asked for - the record they were for was taken back. Each is cancelled with
|
|
28
|
+
* the reason and its to-do aborted; completed ones stay. Answers how many were withdrawn.
|
|
29
|
+
*/
|
|
30
|
+
export declare function withdraw(source: LearningSource, reason: string, context: any): Promise<number>;
|
|
31
|
+
/**
|
|
32
|
+
* A manager cancels an enrolment with a reason (decision 8). An open one is withdrawn; a completed one stays on record as
|
|
33
|
+
* cancelled - never deleted - and whoever asked for it is told in the same transaction.
|
|
34
|
+
*/
|
|
35
|
+
export declare function cancelEnrollment(id: string, reason: string, context: any): Promise<Enrollment>;
|
|
36
|
+
/**
|
|
37
|
+
* The people an audience names now - the domain, departments with those under them, roles and people, by organization's
|
|
38
|
+
* one rule (ADR-0163). Each target must be of this domain.
|
|
39
|
+
*/
|
|
40
|
+
export declare function learnersOf(audiences: {
|
|
41
|
+
scope: string;
|
|
42
|
+
targetId: string;
|
|
43
|
+
targetName?: string;
|
|
44
|
+
}[], context: any): Promise<string[]>;
|
|
45
|
+
export declare function enrollmentOf(tx: EntityManager, domain: {
|
|
46
|
+
id: string;
|
|
47
|
+
}, id: string): Promise<Enrollment>;
|
|
48
|
+
/** The request's own enrolment - one answer for "none" and "not yours". */
|
|
49
|
+
export declare function myEnrollmentOf(context: any, id: string, tx?: EntityManager): Promise<Enrollment>;
|
|
50
|
+
/** The version an enrolment shows: its own once started, the published one before. */
|
|
51
|
+
export declare function shownVersionOf(tx: EntityManager, domain: {
|
|
52
|
+
id: string;
|
|
53
|
+
}, enrollment: Enrollment): Promise<CourseVersion | null>;
|
|
54
|
+
export declare function progressesOf(tx: EntityManager, enrollmentId: string): Promise<UnitProgress[]>;
|
|
55
|
+
/** What still stands between an enrolment and its completion - nothing for a completed one. */
|
|
56
|
+
export declare function missingFor(tx: EntityManager, domain: {
|
|
57
|
+
id: string;
|
|
58
|
+
}, enrollment: Enrollment): Promise<Missing[]>;
|
|
59
|
+
export interface TickResult {
|
|
60
|
+
enrollment: Enrollment;
|
|
61
|
+
progress: UnitProgress;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 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
|
|
65
|
+
* 15 seconds and at most what the screen says, and refuses a video position ahead of what was watched. A total the
|
|
66
|
+
* screen sends is never taken. A unit that reaches its condition is done, and the enrolment is completed when nothing is
|
|
67
|
+
* missing any more.
|
|
68
|
+
*/
|
|
69
|
+
export declare function recordTick(enrollmentId: string, unitId: string, seconds: number, position: number, context: any, now?: Date): Promise<TickResult>;
|
|
70
|
+
/** The learner confirms the version's acknowledgement - recorded once, when they did. */
|
|
71
|
+
export declare function acknowledgeEnrollment(enrollmentId: string, context: any): Promise<Enrollment>;
|
|
72
|
+
export interface DrawnForLearner {
|
|
73
|
+
attempt: QuizAttempt;
|
|
74
|
+
questions: {
|
|
75
|
+
id: string;
|
|
76
|
+
kind: string;
|
|
77
|
+
text: string;
|
|
78
|
+
choices: {
|
|
79
|
+
id: string;
|
|
80
|
+
text: string;
|
|
81
|
+
}[];
|
|
82
|
+
}[];
|
|
83
|
+
}
|
|
84
|
+
/** The questions of an attempt as the learner is drawn them - the choices in the order shown, never whether one is right. */
|
|
85
|
+
export declare function forLearner(attempt: QuizAttempt, questions: CourseQuestion[]): DrawnForLearner;
|
|
86
|
+
export declare function startQuizAttempt(enrollmentId: string, context: any): Promise<DrawnForLearner>;
|
|
87
|
+
export interface QuizResult {
|
|
88
|
+
enrollment: Enrollment;
|
|
89
|
+
score: number;
|
|
90
|
+
passed: boolean;
|
|
91
|
+
attemptsLeft: number | null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Scores an attempt's answers on the server against what it drew (decision 4) - only the score and whether it passed go
|
|
95
|
+
* back, never the right answers. The best score stays on the enrolment; passing may complete it.
|
|
96
|
+
*/
|
|
97
|
+
export declare function submitQuizAttempt(attemptId: string, answers: Record<string, string[]>, context: any): Promise<QuizResult>;
|
|
98
|
+
/** A certificate number: the day completed and the enrolment's own id - one per completion, never reused. */
|
|
99
|
+
export declare const certificateNoOf: (enrollment: {
|
|
100
|
+
id: string;
|
|
101
|
+
}, day: string) => string;
|
|
102
|
+
/**
|
|
103
|
+
* Completes an open enrolment when nothing is missing - every unit done, the least time, the quiz passed, the
|
|
104
|
+
* acknowledgement confirmed. The evidence stays on it; whoever asked for it is told in this same transaction (a handler
|
|
105
|
+
* that fails takes the completion back), and the to-do ends as done.
|
|
106
|
+
*/
|
|
107
|
+
export declare function completeIfMet(tx: EntityManager, domain: any, enrollment: Enrollment, context: any): Promise<Enrollment>;
|
|
108
|
+
/** The open and completed enrolments of the request's person, the open first and the soonest due first. */
|
|
109
|
+
export declare function myEnrollments(context: any): Promise<Enrollment[]>;
|
|
110
|
+
export { isOpen };
|
|
@@ -0,0 +1,417 @@
|
|
|
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, 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.kind === course_unit_1.CourseUnitKind.VIDEO);
|
|
283
|
+
if ('refusal' in verdict)
|
|
284
|
+
throw new shell_1.Refusal('learning-position-ahead', { allowed: verdict.allowed }, `the video cannot be ahead of what was watched (${verdict.allowed} s)`);
|
|
285
|
+
progress.learnedSeconds += verdict.add;
|
|
286
|
+
progress.watchedSeconds = verdict.watchedSeconds;
|
|
287
|
+
progress.positionSeconds = verdict.positionSeconds;
|
|
288
|
+
progress.lastTickAt = now;
|
|
289
|
+
if (!progress.doneAt && (0, progress_rules_1.unitDone)(unit, progress))
|
|
290
|
+
progress.doneAt = now;
|
|
291
|
+
progress.updater = user;
|
|
292
|
+
await repository.save(progress);
|
|
293
|
+
if (verdict.add)
|
|
294
|
+
await tx.getRepository(enrollment_1.Enrollment).increment({ id: enrollment.id }, 'learnedSeconds', verdict.add);
|
|
295
|
+
enrollment = await completeIfMet(tx, domain, await enrollmentOf(tx, domain, enrollment.id), context);
|
|
296
|
+
return { enrollment, progress };
|
|
297
|
+
}
|
|
298
|
+
/** The learner confirms the version's acknowledgement - recorded once, when they did. */
|
|
299
|
+
async function acknowledgeEnrollment(enrollmentId, context) {
|
|
300
|
+
const { domain, user, tx } = context.state;
|
|
301
|
+
let enrollment = await started(tx, domain, await myEnrollmentOf(context, enrollmentId, tx), user);
|
|
302
|
+
const version = await shownVersionOf(tx, domain, enrollment);
|
|
303
|
+
if (!version?.acknowledgement)
|
|
304
|
+
throw new shell_1.Refusal('learning-no-acknowledgement', {}, 'the course asks for no acknowledgement');
|
|
305
|
+
if (!enrollment.acknowledgedAt)
|
|
306
|
+
await tx.getRepository(enrollment_1.Enrollment).update({ id: enrollment.id }, { acknowledgedAt: new Date(), updater: user });
|
|
307
|
+
return await completeIfMet(tx, domain, await enrollmentOf(tx, domain, enrollment.id), context);
|
|
308
|
+
}
|
|
309
|
+
/** The questions of an attempt as the learner is drawn them - the choices in the order shown, never whether one is right. */
|
|
310
|
+
function forLearner(attempt, questions) {
|
|
311
|
+
return {
|
|
312
|
+
attempt,
|
|
313
|
+
questions: attempt.drawn.map(drawn => {
|
|
314
|
+
const question = questions.find(one => one.id === drawn.questionId);
|
|
315
|
+
return {
|
|
316
|
+
id: question.id,
|
|
317
|
+
kind: question.kind,
|
|
318
|
+
text: question.text,
|
|
319
|
+
choices: drawn.choiceIds.map(id => question.choices.find(one => one.id === id)).map(one => ({ id: one.id, text: one.text }))
|
|
320
|
+
};
|
|
321
|
+
})
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Starts an attempt at the quiz: the questions drawn and shuffled, their choices shuffled. An attempt not sent yet is
|
|
326
|
+
* answered again; the version's limit on attempts holds.
|
|
327
|
+
*/
|
|
328
|
+
/**
|
|
329
|
+
* Holds the enrolment for the rest of the request's transaction - an update takes its row lock on every driver, so two
|
|
330
|
+
* attempts of one enrolment are started, counted and sent one after the other. Two starts at once made two unsent
|
|
331
|
+
* attempts, and a limit of one let both be sent (2026-11-08).
|
|
332
|
+
*/
|
|
333
|
+
async function holdEnrollment(tx, domain, enrollment, user) {
|
|
334
|
+
await tx.getRepository(enrollment_1.Enrollment).update({ id: enrollment.id }, { updater: user });
|
|
335
|
+
return await enrollmentOf(tx, domain, enrollment.id);
|
|
336
|
+
}
|
|
337
|
+
async function startQuizAttempt(enrollmentId, context) {
|
|
338
|
+
const { domain, user, tx } = context.state;
|
|
339
|
+
const held = await holdEnrollment(tx, domain, await myEnrollmentOf(context, enrollmentId, tx), user);
|
|
340
|
+
const enrollment = await started(tx, domain, held, user);
|
|
341
|
+
if (enrollment.status === enrollment_1.EnrollmentStatus.COMPLETED)
|
|
342
|
+
throw new shell_1.Refusal('learning-enrollment-completed', {}, 'the course is completed');
|
|
343
|
+
const version = (await shownVersionOf(tx, domain, enrollment));
|
|
344
|
+
const questions = await (0, course_service_1.questionsOf)(tx, version.id);
|
|
345
|
+
if (version.passScore == null || !questions.length)
|
|
346
|
+
throw new shell_1.Refusal('learning-no-quiz', {}, 'the course has no quiz');
|
|
347
|
+
const repository = tx.getRepository(quiz_attempt_1.QuizAttempt);
|
|
348
|
+
const pending = await repository.findOne({ where: { enrollment: { id: enrollment.id }, submittedAt: (0, typeorm_1.IsNull)() } });
|
|
349
|
+
if (pending)
|
|
350
|
+
return forLearner(pending, questions);
|
|
351
|
+
if (version.attemptLimit != null && enrollment.attempts >= version.attemptLimit)
|
|
352
|
+
throw new shell_1.Refusal('learning-attempts-used', { limit: version.attemptLimit }, `all ${version.attemptLimit} attempts are used`);
|
|
353
|
+
const attempt = await repository.save({ domain, enrollment, drawn: (0, progress_rules_1.drawQuestions)(questions, version.questionCount), creator: user, updater: user });
|
|
354
|
+
return forLearner(attempt, questions);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Scores an attempt's answers on the server against what it drew (decision 4) - only the score and whether it passed go
|
|
358
|
+
* back, never the right answers. The best score stays on the enrolment; passing may complete it.
|
|
359
|
+
*/
|
|
360
|
+
async function submitQuizAttempt(attemptId, answers, context) {
|
|
361
|
+
const { domain, user, tx } = context.state;
|
|
362
|
+
const attempt = await tx.getRepository(quiz_attempt_1.QuizAttempt).findOne({ where: { id: attemptId, domain: { id: domain.id } } });
|
|
363
|
+
if (!attempt)
|
|
364
|
+
throw notFound();
|
|
365
|
+
const enrollment = await holdEnrollment(tx, domain, await myEnrollmentOf(context, attempt.enrollmentId, tx), user);
|
|
366
|
+
const version = (await shownVersionOf(tx, domain, enrollment));
|
|
367
|
+
if (version.attemptLimit != null && enrollment.attempts >= version.attemptLimit)
|
|
368
|
+
throw new shell_1.Refusal('learning-attempts-used', { limit: version.attemptLimit }, `all ${version.attemptLimit} attempts are used`);
|
|
369
|
+
const questions = await (0, course_service_1.questionsOf)(tx, version.id);
|
|
370
|
+
const drawn = attempt.drawn.map(one => questions.find(question => question.id === one.questionId)).filter(Boolean);
|
|
371
|
+
const kept = Object.fromEntries(drawn.map(question => [question.id, (answers?.[question.id] ?? []).map(String)]));
|
|
372
|
+
const score = (0, progress_rules_1.scoreOf)(drawn, kept);
|
|
373
|
+
const passed = score >= (version.passScore ?? 101);
|
|
374
|
+
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 });
|
|
375
|
+
if (!claimed.affected)
|
|
376
|
+
throw new shell_1.Refusal('learning-attempt-sent', {}, 'the attempt was sent already');
|
|
377
|
+
await tx.getRepository(enrollment_1.Enrollment).increment({ id: enrollment.id }, 'attempts', 1);
|
|
378
|
+
await tx.getRepository(enrollment_1.Enrollment).update({ id: enrollment.id }, { score: Math.max(enrollment.score ?? 0, score), updater: user });
|
|
379
|
+
const after = await completeIfMet(tx, domain, await enrollmentOf(tx, domain, enrollment.id), context);
|
|
380
|
+
return { enrollment: after, score, passed, attemptsLeft: version.attemptLimit != null ? Math.max(0, version.attemptLimit - after.attempts) : null };
|
|
381
|
+
}
|
|
382
|
+
/* ---------------------------------------------------------------- completing (decision 8) */
|
|
383
|
+
/** A certificate number: the day completed and the enrolment's own id - one per completion, never reused. */
|
|
384
|
+
const certificateNoOf = (enrollment, day) => `LMS-${day.replace(/-/g, '')}-${enrollment.id.replace(/-/g, '').slice(0, 8).toUpperCase()}`;
|
|
385
|
+
exports.certificateNoOf = certificateNoOf;
|
|
386
|
+
/**
|
|
387
|
+
* Completes an open enrolment when nothing is missing - every unit done, the least time, the quiz passed, the
|
|
388
|
+
* acknowledgement confirmed. The evidence stays on it; whoever asked for it is told in this same transaction (a handler
|
|
389
|
+
* that fails takes the completion back), and the to-do ends as done.
|
|
390
|
+
*/
|
|
391
|
+
async function completeIfMet(tx, domain, enrollment, context) {
|
|
392
|
+
if (!isOpen(enrollment.status) || !enrollment.versionId)
|
|
393
|
+
return enrollment;
|
|
394
|
+
if ((await missingFor(tx, domain, enrollment)).length)
|
|
395
|
+
return enrollment;
|
|
396
|
+
const now = new Date();
|
|
397
|
+
const claimed = await tx
|
|
398
|
+
.getRepository(enrollment_1.Enrollment)
|
|
399
|
+
.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 });
|
|
400
|
+
if (!claimed.affected)
|
|
401
|
+
return await enrollmentOf(tx, domain, enrollment.id);
|
|
402
|
+
const completed = await enrollmentOf(tx, domain, enrollment.id);
|
|
403
|
+
await (0, learning_outcome_1.learningOutcomeOf)(completed.sourceKind)?.completed(completed, context);
|
|
404
|
+
await completeTodo(tx, domain, completed, context.state.user);
|
|
405
|
+
return completed;
|
|
406
|
+
}
|
|
407
|
+
/* ---------------------------------------------------------------- whom an enrolment is for */
|
|
408
|
+
/** The open and completed enrolments of the request's person, the open first and the soonest due first. */
|
|
409
|
+
async function myEnrollments(context) {
|
|
410
|
+
const { domain, user } = context.state;
|
|
411
|
+
const rows = await (0, course_service_1.learningManagerOf)(context)
|
|
412
|
+
.getRepository(enrollment_1.Enrollment)
|
|
413
|
+
.find({ where: { domain: { id: domain.id }, user: { id: user.id }, status: (0, typeorm_1.In)([...enrollment_1.OPEN_ENROLLMENT_STATUSES, enrollment_1.EnrollmentStatus.COMPLETED]) } });
|
|
414
|
+
const rank = (one) => (isOpen(one.status) ? 0 : 1);
|
|
415
|
+
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));
|
|
416
|
+
}
|
|
417
|
+
//# sourceMappingURL=enrollment-service.js.map
|