coursekit-lms 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +76 -0
- package/README.md +127 -26
- package/dist/cli/index.js +7139 -1633
- package/dist/cli/index.js.map +1 -1
- package/dist/server/index.js +7128 -1655
- package/dist/server/index.js.map +1 -1
- package/dist/types/server/config.d.ts +4 -0
- package/dist/types/server/db/migrations/002_email.d.ts +8 -0
- package/dist/types/server/db/migrations/003_groups_cohorts.d.ts +7 -0
- package/dist/types/server/db/migrations/004_completion_badges.d.ts +8 -0
- package/dist/types/server/db/migrations/005_question_bank.d.ts +11 -0
- package/dist/types/server/db/migrations/006_grade_categories.d.ts +11 -0
- package/dist/types/server/db/schema-completion.d.ts +79 -0
- package/dist/types/server/db/schema.d.ts +165 -5
- package/dist/types/server/index.d.ts +7 -0
- package/dist/types/server/lib/events.d.ts +105 -0
- package/dist/types/server/routes/badges.d.ts +4 -0
- package/dist/types/server/routes/certificates.d.ts +3 -0
- package/dist/types/server/routes/cohorts.d.ts +6 -0
- package/dist/types/server/routes/completion.d.ts +4 -0
- package/dist/types/server/routes/email.d.ts +13 -0
- package/dist/types/server/routes/grade-categories.d.ts +4 -0
- package/dist/types/server/routes/groups.d.ts +4 -0
- package/dist/types/server/routes/question-bank.d.ts +4 -0
- package/dist/types/server/seed/demo-completion.d.ts +2 -0
- package/dist/types/server/seed/demo-email.d.ts +2 -0
- package/dist/types/server/seed/demo-grade-categories.d.ts +6 -0
- package/dist/types/server/seed/demo-groups.d.ts +6 -0
- package/dist/types/server/seed/demo-question-bank.d.ts +20 -0
- package/dist/types/server/services/badges.d.ts +39 -0
- package/dist/types/server/services/certificates.d.ts +42 -0
- package/dist/types/server/services/cohorts.d.ts +64 -0
- package/dist/types/server/services/completion.d.ts +63 -0
- package/dist/types/server/services/course-total.d.ts +107 -0
- package/dist/types/server/services/email/config.d.ts +55 -0
- package/dist/types/server/services/email/digests.d.ts +57 -0
- package/dist/types/server/services/email/outbox.d.ts +61 -0
- package/dist/types/server/services/email/preferences.d.ts +25 -0
- package/dist/types/server/services/email/service.d.ts +116 -0
- package/dist/types/server/services/email/templates.d.ts +74 -0
- package/dist/types/server/services/email/tokens.d.ts +11 -0
- package/dist/types/server/services/email/transport.d.ts +29 -0
- package/dist/types/server/services/enrolments.d.ts +32 -0
- package/dist/types/server/services/grade-categories.d.ts +31 -0
- package/dist/types/server/services/gradebook.d.ts +18 -0
- package/dist/types/server/services/groups.d.ts +90 -0
- package/dist/types/server/services/notify.d.ts +4 -1
- package/dist/types/server/services/question-bank.d.ts +53 -0
- package/dist/types/server/services/question-types.d.ts +146 -0
- package/dist/types/server/services/quiz-slots.d.ts +33 -0
- package/dist/types/server/services/quiz.d.ts +45 -14
- package/dist/types/shared/completion.d.ts +214 -0
- package/dist/types/shared/email.d.ts +117 -0
- package/dist/types/shared/grades.d.ts +18 -0
- package/dist/types/shared/groups.d.ts +17 -0
- package/dist/types/shared/permissions.d.ts +1 -1
- package/dist/types/shared/types.d.ts +268 -2
- package/dist/web/assets/{ActivityEditor-BVSZUV8l.js → ActivityEditor-BNG3aTQa.js} +2 -2
- package/dist/web/assets/ActivityPage-i0XHYD2Q.js +1 -0
- package/dist/web/assets/AdminBadgesPage-DvpxIg1P.js +1 -0
- package/dist/web/assets/AdminCohortsPage-B5PWBkjp.js +3 -0
- package/dist/web/assets/AdminCoursesPage-Dm1ECbS-.js +1 -0
- package/dist/web/assets/AdminEmailPage-D3E_Db1_.js +1 -0
- package/dist/web/assets/AdminLayout-BVeduyCQ.js +1 -0
- package/dist/web/assets/{AdminOverviewPage-DnTrdGbr.js → AdminOverviewPage-BaCKvhgr.js} +1 -1
- package/dist/web/assets/{AdminSettingsPage-B82cX8xU.js → AdminSettingsPage-B5Ag5K15.js} +1 -1
- package/dist/web/assets/AdminUsersPage-BVCG65EK.js +1 -0
- package/dist/web/assets/{AnnouncementsPage-BKW30k0Z.js → AnnouncementsPage-C0OAzyvW.js} +1 -1
- package/dist/web/assets/BadgePage-B3Ecudas.js +1 -0
- package/dist/web/assets/CalendarPage-CEks5F4m.js +1 -0
- package/dist/web/assets/{CatalogPage-BiMgSSBR.js → CatalogPage-e7lVtwUN.js} +1 -1
- package/dist/web/assets/CertificatePage-_eSGt8R-.js +9 -0
- package/dist/web/assets/CompletionPage-Dxp-ulA_.js +1 -0
- package/dist/web/assets/CourseBadgesPage-Vi3P1Lnc.js +1 -0
- package/dist/web/assets/CourseContentPage-IFlhVsO5.js +1 -0
- package/dist/web/assets/CourseLayout-BqwXol8L.js +1 -0
- package/dist/web/assets/CourseSettingsPage-BIagLirb.js +1 -0
- package/dist/web/assets/CreateCoursePage-BBcdiTtz.js +1 -0
- package/dist/web/assets/{DiscussionPage-CWwVpFQV.js → DiscussionPage-C23QoCSw.js} +1 -1
- package/dist/web/assets/GradebookSetupPage-a5GH4xIk.js +1 -0
- package/dist/web/assets/GradesPage-CY6MtJxs.js +1 -0
- package/dist/web/assets/GroupsPage-DS3HFeC4.js +1 -0
- package/dist/web/assets/{MyCoursesPage-Dd-Oaygv.js → MyCoursesPage-Ckj-1SCA.js} +1 -1
- package/dist/web/assets/{NotFoundPage-BRquC7-l.js → NotFoundPage-BmwVsGAy.js} +1 -1
- package/dist/web/assets/NotificationsPage-DBRM37F1.js +1 -0
- package/dist/web/assets/ParticipantsPage-DV4Mjfxo.js +1 -0
- package/dist/web/assets/ProfilePage-BqG55_02.js +1 -0
- package/dist/web/assets/QuestionAnswer-CJIoWSz2.js +1 -0
- package/dist/web/assets/QuestionBankPage-BkI44c4K.js +1 -0
- package/dist/web/assets/QuizAttemptPage-DQVfbLKI.js +1 -0
- package/dist/web/assets/QuizEditorPage-muk-KVG1.js +1 -0
- package/dist/web/assets/SubmissionsPage-Dx97JOzE.js +1 -0
- package/dist/web/assets/UnsubscribePage-BPLiTiaG.js +1 -0
- package/dist/web/assets/VerifyCertificatePage-Cw9iXN3C.js +1 -0
- package/dist/web/assets/achievements-DaIfUTKU.js +1 -0
- package/dist/web/assets/{arrow-up-LHDup5m4.js → arrow-up-lI30bvj5.js} +1 -1
- package/dist/web/assets/badge-art-QPo-pYql.js +1 -0
- package/dist/web/assets/badge-card-ByT0wR6q.js +1 -0
- package/dist/web/assets/badge-dialog-p2zTk4h0.js +1 -0
- package/dist/web/assets/{ban-D3Vsxg_g.js → ban-DEiI8npI.js} +1 -1
- package/dist/web/assets/bank-S3XEFPfe.js +3 -0
- package/dist/web/assets/bell-off-Bo2RE0kn.js +1 -0
- package/dist/web/assets/calendar-range-Cfg-P4Md.js +1 -0
- package/dist/web/assets/certificate-sheet-DzW0lfzR.js +2 -0
- package/dist/web/assets/chevron-left-Bu6IJANV.js +1 -0
- package/dist/web/assets/circle-dashed-D34ZjnSx.js +1 -0
- package/dist/web/assets/clock-DPBmdKAi.js +1 -0
- package/dist/web/assets/cohorts-DL0Dsxva.js +1 -0
- package/dist/web/assets/completion-2z7I-ypT.js +1 -0
- package/dist/web/assets/contact-NCWQa7wc.js +1 -0
- package/dist/web/assets/{context-BLVW7NB7.js → context-D8W_QqNi.js} +1 -1
- package/dist/web/assets/{copy-Bxxjq6zo.js → copy-B5IKRMFo.js} +1 -1
- package/dist/web/assets/download-BrtK5sVk.js +1 -0
- package/dist/web/assets/{ellipsis-c2POIN-Y.js → ellipsis-BDmYLoyn.js} +1 -1
- package/dist/web/assets/email-BZ3kGs-R.js +1 -0
- package/dist/web/assets/flag-DOzXVys0.js +1 -0
- package/dist/web/assets/folder-input-M2p_UJZX.js +1 -0
- package/dist/web/assets/{library-3WG9oLCb.js → folder-tree-B-DoLXMB.js} +1 -1
- package/dist/web/assets/frame-DZh5g5b3.js +1 -0
- package/dist/web/assets/globe-DDTr53UY.js +1 -0
- package/dist/web/assets/grades-ogaD0MDO.js +1 -0
- package/dist/web/assets/groups-CrYV_AFp.js +1 -0
- package/dist/web/assets/{hooks-BBARn-DA.js → hooks-EFhyJ5yU.js} +1 -1
- package/dist/web/assets/hourglass-BKca6Cje.js +1 -0
- package/dist/web/assets/inbox-x1U4YU-c.js +1 -0
- package/dist/web/assets/index-BdPmMS6n.css +2 -0
- package/dist/web/assets/index-CEZdqKdi.js +50 -0
- package/dist/web/assets/{key-round-B_KI-brR.js → key-round-fzvV-etw.js} +1 -1
- package/dist/web/assets/library-Bcm33ouq.js +1 -0
- package/dist/web/assets/lightbulb-CjSpJ1_v.js +1 -0
- package/dist/web/assets/{lock-BjbqwA_0.js → lock-C2edVDOc.js} +1 -1
- package/dist/web/assets/mail-CQ9yiBph.js +1 -0
- package/dist/web/assets/mail-x-B6oBqlcw.js +1 -0
- package/dist/web/assets/{markdown-ykrkPMbn.js → markdown-HNlXovsL.js} +3 -3
- package/dist/web/assets/message-square-text-wvO9_guT.js +1 -0
- package/dist/web/assets/{misc-DvgDEI3I.js → misc-CyGhN6HT.js} +1 -1
- package/dist/web/assets/{pencil-p0GQmIMo.js → pencil-DFUpj3YP.js} +1 -1
- package/dist/web/assets/{pin-DlYC3uec.js → pin-DNUQ6-WX.js} +1 -1
- package/dist/web/assets/revoke-dialog-DjBKaFTV.js +1 -0
- package/dist/web/assets/rotate-ccw-yBj9Ri49.js +1 -0
- package/dist/web/assets/scroll-text-RmPlZi3F.js +1 -0
- package/dist/web/assets/{send-mxSHcdcD.js → send-BnVkFV8w.js} +1 -1
- package/dist/web/assets/{settings-DRKWzSHN.js → settings-BxdCrDf8.js} +1 -1
- package/dist/web/assets/shield-x-RpNHS0o8.js +1 -0
- package/dist/web/assets/shuffle-C1aB_4dp.js +1 -0
- package/dist/web/assets/target-G9Q_WQLB.js +1 -0
- package/dist/web/assets/trophy-BFFngFEh.js +1 -0
- package/dist/web/assets/user-minus-CkOPT3ak.js +1 -0
- package/dist/web/assets/users-round-CNhv0Whm.js +1 -0
- package/dist/web/index.html +4 -4
- package/package.json +6 -1
- package/dist/web/assets/ActivityPage-DPmSV_mU.js +0 -1
- package/dist/web/assets/AdminCoursesPage-uaSHNtzf.js +0 -1
- package/dist/web/assets/AdminLayout-DqoShZGn.js +0 -1
- package/dist/web/assets/AdminUsersPage-3d2F9AEl.js +0 -1
- package/dist/web/assets/CalendarPage-CLRWyTNT.js +0 -1
- package/dist/web/assets/CourseContentPage-BIDH0UbG.js +0 -1
- package/dist/web/assets/CourseLayout-ql01LEmj.js +0 -1
- package/dist/web/assets/CourseSettingsPage-CReoPqOa.js +0 -1
- package/dist/web/assets/CreateCoursePage-DFCHlq5M.js +0 -1
- package/dist/web/assets/GradesPage-Bu5vphcG.js +0 -1
- package/dist/web/assets/NotificationsPage-LJvqb6Dj.js +0 -1
- package/dist/web/assets/ParticipantsPage-wFxiphna.js +0 -1
- package/dist/web/assets/ProfilePage-CzfhacAX.js +0 -1
- package/dist/web/assets/QuizAttemptPage-CEAV6wAL.js +0 -1
- package/dist/web/assets/QuizEditorPage-DS_czQVM.js +0 -3
- package/dist/web/assets/SubmissionsPage-CQjcx09G.js +0 -1
- package/dist/web/assets/chevron-left-D6IMQD6N.js +0 -1
- package/dist/web/assets/frame-CGabirLa.js +0 -1
- package/dist/web/assets/index-B29bTBiJ.js +0 -50
- package/dist/web/assets/index-WxCvsbJq.css +0 -2
- package/dist/web/assets/message-square-text-fe24gbEU.js +0 -1
- package/dist/web/assets/trophy-Cch2iF1m.js +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type EmailCategoryId } from '../../../shared/email.js';
|
|
2
|
+
export interface EmailBrand {
|
|
3
|
+
name: string;
|
|
4
|
+
brandColor: string;
|
|
5
|
+
}
|
|
6
|
+
export interface RenderedEmail {
|
|
7
|
+
subject: string;
|
|
8
|
+
html: string;
|
|
9
|
+
text: string;
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
/** Links shared by every email to one person. Null when the site has no public URL. */
|
|
13
|
+
export interface EmailLinks {
|
|
14
|
+
preferences: string | null;
|
|
15
|
+
unsubscribe: string | null;
|
|
16
|
+
}
|
|
17
|
+
export declare function escapeHtml(value: string): string;
|
|
18
|
+
/** A single-line header value: no CR/LF or other control characters, collapsed spaces, bounded length. */
|
|
19
|
+
export declare function headerText(value: string, max?: number): string;
|
|
20
|
+
/**
|
|
21
|
+
* Notification bodies can be the start of a Markdown post (announcements do this): drop the common
|
|
22
|
+
* syntax so emails read as plain text. Paired markers only, so "snake_case" and "5 * 3" survive.
|
|
23
|
+
*/
|
|
24
|
+
export declare function markdownToText(value: string): string;
|
|
25
|
+
/** The site's public URL without a trailing slash, or null when it is missing or not http(s). */
|
|
26
|
+
export declare function normalizeBaseUrl(publicUrl: string | null | undefined): string | null;
|
|
27
|
+
/** An absolute link for an app path such as "/courses/x", or null without a public URL. */
|
|
28
|
+
export declare function absoluteUrl(base: string | null, path: string | null | undefined): string | null;
|
|
29
|
+
/** Brand colours for buttons and links in light and dark mode, all with readable contrast. */
|
|
30
|
+
export declare function brandPalette(color: string): {
|
|
31
|
+
brand: string;
|
|
32
|
+
onBrand: string;
|
|
33
|
+
link: string;
|
|
34
|
+
darkLink: string;
|
|
35
|
+
};
|
|
36
|
+
/** List-Unsubscribe headers (RFC 2369 and RFC 8058 one-click), plus headers that keep auto-replies away. */
|
|
37
|
+
export declare function emailHeaders(unsubscribeUrl: string | null): Record<string, string>;
|
|
38
|
+
export interface NotificationEmailInput {
|
|
39
|
+
brand: EmailBrand;
|
|
40
|
+
links: EmailLinks;
|
|
41
|
+
base: string | null;
|
|
42
|
+
title: string;
|
|
43
|
+
body: string;
|
|
44
|
+
link: string | null;
|
|
45
|
+
category: EmailCategoryId;
|
|
46
|
+
}
|
|
47
|
+
export declare function renderNotificationEmail(input: NotificationEmailInput): RenderedEmail;
|
|
48
|
+
export interface DigestItem {
|
|
49
|
+
title: string;
|
|
50
|
+
body: string;
|
|
51
|
+
link: string | null;
|
|
52
|
+
category: EmailCategoryId;
|
|
53
|
+
createdAt: string;
|
|
54
|
+
}
|
|
55
|
+
export interface DigestEmailInput {
|
|
56
|
+
brand: EmailBrand;
|
|
57
|
+
links: EmailLinks;
|
|
58
|
+
base: string | null;
|
|
59
|
+
period: 'daily' | 'weekly';
|
|
60
|
+
/** Start of the period covered (ISO): the previous digest, or one period ago. */
|
|
61
|
+
since: string;
|
|
62
|
+
/** Newest first. Only the first `limit` are listed. */
|
|
63
|
+
items: DigestItem[];
|
|
64
|
+
timezone: string;
|
|
65
|
+
limit?: number;
|
|
66
|
+
}
|
|
67
|
+
export declare function renderDigestEmail(input: DigestEmailInput): RenderedEmail;
|
|
68
|
+
export declare function renderTestEmail(input: {
|
|
69
|
+
brand: EmailBrand;
|
|
70
|
+
links: EmailLinks;
|
|
71
|
+
transportName: string;
|
|
72
|
+
sentAt: string;
|
|
73
|
+
timezone: string;
|
|
74
|
+
}): RenderedEmail;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type EmailCategoryId } from '../../../shared/email.js';
|
|
2
|
+
import type { DB } from '../../db/types.js';
|
|
3
|
+
export interface UnsubscribeTarget {
|
|
4
|
+
userId: string;
|
|
5
|
+
/** null: every email. */
|
|
6
|
+
category: EmailCategoryId | null;
|
|
7
|
+
}
|
|
8
|
+
/** The site's signing secret, created on first use (safely, if several processes race), then cached. */
|
|
9
|
+
export declare function emailSecret(db: DB): Promise<string>;
|
|
10
|
+
export declare function signUnsubscribeToken(secret: string, target: UnsubscribeTarget): string;
|
|
11
|
+
export declare function verifyUnsubscribeToken(secret: string, token: string): UnsubscribeTarget | null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type EmailMessage, type EmailTransport, type ResolvedEmailConfig } from './config.js';
|
|
2
|
+
/** A configured way of delivering email. */
|
|
3
|
+
export interface Sender {
|
|
4
|
+
readonly kind: 'smtp' | 'log' | 'custom';
|
|
5
|
+
/** e.g. "SMTP", "Log" or a custom transport's name. */
|
|
6
|
+
readonly name: string;
|
|
7
|
+
/** e.g. "smtp.example.com:587" or the folder emails are saved to. */
|
|
8
|
+
readonly detail: string | null;
|
|
9
|
+
/** Resolves once the transport can send; rejects with a helpful message when it can't (e.g. nodemailer is missing). */
|
|
10
|
+
ready(): Promise<void>;
|
|
11
|
+
send(message: EmailMessage): Promise<void>;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare const MISSING_NODEMAILER = "SMTP email needs the \"nodemailer\" package. Install it with: npm install nodemailer";
|
|
15
|
+
export type ModuleLoader = () => Promise<unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* nodemailer options from an smtp:// or smtps:// URL. Credentials are percent-decoded, query parameters
|
|
18
|
+
* become options (numbers and booleans converted, `tls.*` nested) and timeouts default to values short enough
|
|
19
|
+
* that a stuck server can't hold a message for long.
|
|
20
|
+
*/
|
|
21
|
+
export declare function smtpOptionsFromUrl(smtpUrl: string): Record<string, unknown>;
|
|
22
|
+
export declare function smtpSender(smtpUrl: string, load?: ModuleLoader): Sender;
|
|
23
|
+
/** A complete RFC 5322 message, so saved emails open in any mail app. */
|
|
24
|
+
export declare function toMime(message: EmailMessage, date?: Date): string;
|
|
25
|
+
/** Prints each email and saves it as .eml (opens in any mail app) and .html (opens in a browser). */
|
|
26
|
+
export declare function logSender(dir: string): Sender;
|
|
27
|
+
export declare function customSender(transport: EmailTransport): Sender;
|
|
28
|
+
/** The sender for the configured transport, or null when email is off. */
|
|
29
|
+
export declare function createSender(config: ResolvedEmailConfig, dataDir: string): Sender | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CourseRole } from '../../shared/types.js';
|
|
2
|
+
import type { AppDeps } from '../context.js';
|
|
3
|
+
import type { CourseRow } from '../db/schema.js';
|
|
4
|
+
import type { DB } from '../db/types.js';
|
|
5
|
+
type Course = Pick<CourseRow, 'id' | 'slug' | 'title'>;
|
|
6
|
+
/**
|
|
7
|
+
* Inserts active enrolments for the users who aren't enrolled in the course yet, and returns their ids.
|
|
8
|
+
* Anyone who already has an enrolment (any role, active or suspended) is left as they are. Pass a transaction
|
|
9
|
+
* to make this part of a larger change, then call {@link announceEnrolments} once it has committed.
|
|
10
|
+
*/
|
|
11
|
+
export declare function insertEnrolments(db: DB, course: Course, userIds: Iterable<string>, role: CourseRole): Promise<string[]>;
|
|
12
|
+
export interface EnrolmentAnnouncement {
|
|
13
|
+
/** Who enrolled them, named in the notification. */
|
|
14
|
+
actor: {
|
|
15
|
+
name: string;
|
|
16
|
+
} | null;
|
|
17
|
+
/** How they were enrolled, e.g. "through the cohort Class of 2027". */
|
|
18
|
+
via?: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** Notifies newly enrolled people and emits `enrolment.created` for each of them. */
|
|
21
|
+
export declare function announceEnrolments(deps: Pick<AppDeps, 'db' | 'events'>, course: Course, userIds: string[], role: CourseRole, { actor, via }: EnrolmentAnnouncement): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Enrols other people in a course: the one code path behind "Enrol people" and cohort enrolment.
|
|
24
|
+
* Skips anyone already enrolled, notifies the new participants and emits `enrolment.created` for each.
|
|
25
|
+
* Returns the ids of the people who were newly enrolled.
|
|
26
|
+
*/
|
|
27
|
+
export declare function enrolUsers(deps: Pick<AppDeps, 'db' | 'events'>, input: {
|
|
28
|
+
course: Course;
|
|
29
|
+
userIds: Iterable<string>;
|
|
30
|
+
role: CourseRole;
|
|
31
|
+
} & EnrolmentAnnouncement): Promise<string[]>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gradebook setup: a course's categories (name, weight, drop-lowest, order), the category and
|
|
3
|
+
* weight of each graded activity, and the aggregation used for the course total.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import type { GradebookSetup, GradebookSetupInput } from '../../shared/types.js';
|
|
7
|
+
import type { DB } from '../db/types.js';
|
|
8
|
+
export declare const gradebookSetupSchema: z.ZodObject<{
|
|
9
|
+
aggregation: z.ZodEnum<{
|
|
10
|
+
natural: "natural";
|
|
11
|
+
weighted: "weighted";
|
|
12
|
+
}>;
|
|
13
|
+
categories: z.ZodArray<z.ZodObject<{
|
|
14
|
+
id: z.ZodString;
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
weight: z.ZodNumber;
|
|
17
|
+
dropLowest: z.ZodNumber;
|
|
18
|
+
}, z.core.$strip>>;
|
|
19
|
+
items: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
20
|
+
activityId: z.ZodString;
|
|
21
|
+
categoryId: z.ZodString;
|
|
22
|
+
weight: z.ZodNullable<z.ZodNumber>;
|
|
23
|
+
}, z.core.$strip>>>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
export declare function getGradebookSetup(db: DB, courseId: string): Promise<GradebookSetup>;
|
|
26
|
+
/**
|
|
27
|
+
* Replaces a course's gradebook setup in one transaction. Categories missing from the input are
|
|
28
|
+
* deleted and their activities move to the default category (whose id is the course id). Activities
|
|
29
|
+
* missing from `items` keep their settings. Returns the saved setup.
|
|
30
|
+
*/
|
|
31
|
+
export declare function saveGradebookSetup(db: DB, courseId: string, input: GradebookSetupInput): Promise<GradebookSetup>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the gradebook (staff) and "my grades" (student) payloads from the course-total maths.
|
|
3
|
+
*/
|
|
4
|
+
import type { Gradebook, MyGrades } from '../../shared/types.js';
|
|
5
|
+
import type { DB } from '../db/types.js';
|
|
6
|
+
import { type GradeItemInfo, type GradeSetup } from './course-total.js';
|
|
7
|
+
export interface GradebookStudent {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
email: string;
|
|
11
|
+
avatarUrl: string | null;
|
|
12
|
+
}
|
|
13
|
+
/** Items grouped by category (in category order), course order within each category. */
|
|
14
|
+
export declare function itemsInCategoryOrder(setup: GradeSetup): GradeItemInfo[];
|
|
15
|
+
/** The staff gradebook: every item (hidden ones too) for the given students. */
|
|
16
|
+
export declare function buildCourseGradebook(db: DB, courseId: string, students: GradebookStudent[]): Promise<Gradebook>;
|
|
17
|
+
/** A student's own grades. Hidden activities are left out, so they don't count towards the total either. */
|
|
18
|
+
export declare function buildStudentGrades(db: DB, courseId: string, userId: string): Promise<MyGrades>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type GroupSplit } from '../../shared/groups.js';
|
|
2
|
+
import type { CourseGroups, GroupMembersAdded, GroupRef } from '../../shared/types.js';
|
|
3
|
+
import type { AppDeps } from '../context.js';
|
|
4
|
+
import type { CourseGroupRow, CourseRow } from '../db/schema.js';
|
|
5
|
+
import type { DB } from '../db/types.js';
|
|
6
|
+
import type { CourseAccess } from './access.js';
|
|
7
|
+
type Deps = Pick<AppDeps, 'db' | 'events'>;
|
|
8
|
+
/** Natural, case-insensitive order: "Group 2" comes before "Group 10". */
|
|
9
|
+
export declare function byName(a: {
|
|
10
|
+
name: string;
|
|
11
|
+
}, b: {
|
|
12
|
+
name: string;
|
|
13
|
+
}): number;
|
|
14
|
+
/** Staff see every group and who is in it. Students only see the groups they belong to. */
|
|
15
|
+
export declare function canSeeAllGroups(access: CourseAccess): boolean;
|
|
16
|
+
/** Subquery with the members of a group, for `where('enrolments.userId', 'in', groupMemberIds(db, id))`. */
|
|
17
|
+
export declare function groupMemberIds(db: DB, groupId: string): import("kysely").SelectQueryBuilder<import("../db/schema.js").Database & {
|
|
18
|
+
gm: import("../db/schema.js").CourseGroupMembersTable;
|
|
19
|
+
}, "gm", {
|
|
20
|
+
userId: string;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Resolves a `groupId` filter. The group must belong to the course and be one the viewer may see
|
|
24
|
+
* (any group for staff, their own for students); otherwise it is "not found".
|
|
25
|
+
*/
|
|
26
|
+
export declare function findVisibleGroup(db: DB, access: CourseAccess, groupId: string): Promise<GroupRef>;
|
|
27
|
+
/** The groups a user belongs to in a course. */
|
|
28
|
+
export declare function groupsOfUser(db: DB, courseId: string, userId: string): Promise<GroupRef[]>;
|
|
29
|
+
/** Each person's groups in the course, limited to the groups the viewer may see. One query for the whole course. */
|
|
30
|
+
export declare function groupsByUser(db: DB, access: CourseAccess): Promise<Map<string, GroupRef[]>>;
|
|
31
|
+
/**
|
|
32
|
+
* The groups the viewer may see, each with its enrolled members. People who left the course keep their
|
|
33
|
+
* membership rows, but they are hidden here and come back if they are enrolled again.
|
|
34
|
+
*/
|
|
35
|
+
export declare function listGroups(db: DB, access: CourseAccess): Promise<CourseGroups>;
|
|
36
|
+
export declare function loadGroup(db: DB, courseId: string, groupId: string): Promise<CourseGroupRow>;
|
|
37
|
+
/** Unique index violations on SQLite and PostgreSQL. */
|
|
38
|
+
export declare function isUniqueViolation(err: unknown): boolean;
|
|
39
|
+
export declare function createGroup(deps: Deps, course: Pick<CourseRow, 'id'>, input: {
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
courseId: string;
|
|
44
|
+
createdAt: string;
|
|
45
|
+
description: string;
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
updatedAt: string;
|
|
49
|
+
}>;
|
|
50
|
+
export declare function updateGroup(deps: Deps, group: CourseGroupRow, input: {
|
|
51
|
+
name?: string | undefined;
|
|
52
|
+
description?: string | undefined;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
name: string;
|
|
55
|
+
description: string;
|
|
56
|
+
updatedAt: string;
|
|
57
|
+
courseId: string;
|
|
58
|
+
createdAt: string;
|
|
59
|
+
id: string;
|
|
60
|
+
}>;
|
|
61
|
+
export declare function deleteGroup(deps: Deps, group: CourseGroupRow): Promise<void>;
|
|
62
|
+
/** Adds enrolled people to a group. People already in it, and anyone not enrolled in the course, are reported back. */
|
|
63
|
+
export declare function addGroupMembers(deps: Deps, group: CourseGroupRow, userIds: string[]): Promise<GroupMembersAdded>;
|
|
64
|
+
export declare function removeGroupMember(deps: Deps, group: CourseGroupRow, userId: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Shuffles people into balanced groups: `groups` makes `size` groups; `members` makes groups of at most
|
|
67
|
+
* `size` people, using as few groups as that allows. Group sizes never differ by more than one.
|
|
68
|
+
*/
|
|
69
|
+
export declare function planGroups<T>(people: readonly T[], split: GroupSplit, size: number, random?: (max: number) => number): T[][];
|
|
70
|
+
export interface AutoCreateInput {
|
|
71
|
+
split: GroupSplit;
|
|
72
|
+
size: number;
|
|
73
|
+
/** Naming scheme, see `groupNames` in shared/groups.ts. */
|
|
74
|
+
naming: string;
|
|
75
|
+
/** Only place active students who aren't in any group yet. */
|
|
76
|
+
onlyUngrouped: boolean;
|
|
77
|
+
}
|
|
78
|
+
/** Splits the course's active students into new groups at random, balancing their sizes. */
|
|
79
|
+
export declare function autoCreateGroups(deps: Deps, course: Pick<CourseRow, 'id'>, input: AutoCreateInput): Promise<{
|
|
80
|
+
group: {
|
|
81
|
+
id: string;
|
|
82
|
+
courseId: string;
|
|
83
|
+
name: string;
|
|
84
|
+
description: string;
|
|
85
|
+
createdAt: string;
|
|
86
|
+
updatedAt: string;
|
|
87
|
+
};
|
|
88
|
+
userIds: string[];
|
|
89
|
+
}[]>;
|
|
90
|
+
export {};
|
|
@@ -5,6 +5,9 @@ export interface NotificationInput {
|
|
|
5
5
|
body?: string;
|
|
6
6
|
link?: string | null;
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Sends an in-app notification to each user (deduplicated), and queues an email for those who get one for
|
|
10
|
+
* each notification (see services/email). Email problems never make this fail.
|
|
11
|
+
*/
|
|
9
12
|
export declare function notify(db: DB, userIds: Iterable<string>, input: NotificationInput): Promise<void>;
|
|
10
13
|
export declare function courseMemberIds(db: DB, courseId: string, roles?: string[]): Promise<string[]>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { BankQuestion, BankQuestionSummary, Paginated, QuestionCategory, QuestionType, QuestionUsage } from '../../shared/types.js';
|
|
2
|
+
import type { Transaction } from 'kysely';
|
|
3
|
+
import type { DB } from '../db/types.js';
|
|
4
|
+
import type { Database, QuestionCategoryRow, QuestionRow } from '../db/schema.js';
|
|
5
|
+
import { type QuestionInput } from './question-types.js';
|
|
6
|
+
export declare const DEFAULT_CATEGORY_NAME = "Default";
|
|
7
|
+
/** Runs `fn` in a transaction, or in the caller's one if `db` already is a transaction. */
|
|
8
|
+
export declare function transact<T>(db: DB, fn: (trx: Transaction<Database>) => Promise<T>): Promise<T>;
|
|
9
|
+
/** Categories in tree order (each parent followed by its subcategories), siblings by position then name. */
|
|
10
|
+
export declare function sortCategories<T extends Pick<QuestionCategoryRow, 'id' | 'parentId' | 'position' | 'name'>>(rows: T[]): T[];
|
|
11
|
+
/** The category and everything below it. */
|
|
12
|
+
export declare function subtreeIds(rows: Pick<QuestionCategoryRow, 'id' | 'parentId'>[], id: string): string[];
|
|
13
|
+
/** The categories a question in `id` is found under: itself and its parents. */
|
|
14
|
+
export declare function ancestorIds(rows: Pick<QuestionCategoryRow, 'id' | 'parentId'>[], id: string): string[];
|
|
15
|
+
export declare function loadCategories(db: DB, courseId: string): Promise<QuestionCategoryRow[]>;
|
|
16
|
+
/** Every course's bank has at least one category; the first is created on demand. */
|
|
17
|
+
export declare function ensureCategories(db: DB, courseId: string): Promise<QuestionCategoryRow[]>;
|
|
18
|
+
export declare function listCategories(db: DB, courseId: string): Promise<QuestionCategory[]>;
|
|
19
|
+
export declare function createCategory(db: DB, courseId: string, input: {
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
parentId: string | null;
|
|
23
|
+
}): Promise<QuestionCategoryRow>;
|
|
24
|
+
export declare function updateCategory(db: DB, category: QuestionCategoryRow, input: {
|
|
25
|
+
name?: string | undefined;
|
|
26
|
+
description?: string | undefined;
|
|
27
|
+
parentId?: string | null | undefined;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
/** Deletes a category. Its questions, subcategories and random quiz slots move to `moveTo` first. */
|
|
30
|
+
export declare function deleteCategory(db: DB, category: QuestionCategoryRow, moveTo: string | null): Promise<void>;
|
|
31
|
+
export interface QuestionFilter {
|
|
32
|
+
categoryId?: string | undefined;
|
|
33
|
+
includeSubcategories?: boolean | undefined;
|
|
34
|
+
q?: string | undefined;
|
|
35
|
+
type?: QuestionType | undefined;
|
|
36
|
+
page: number;
|
|
37
|
+
pageSize: number;
|
|
38
|
+
}
|
|
39
|
+
type SummaryRow = Pick<QuestionRow, 'id' | 'type' | 'name' | 'prompt' | 'points' | 'categoryId' | 'updatedAt'>;
|
|
40
|
+
export declare function summarizeQuestions(db: DB, rows: SummaryRow[], categories: QuestionCategoryRow[]): Promise<BankQuestionSummary[]>;
|
|
41
|
+
export declare function listQuestions(db: DB, courseId: string, filter: QuestionFilter): Promise<Paginated<BankQuestionSummary>>;
|
|
42
|
+
/** Quizzes that use a question, directly or through a random slot whose category includes it. */
|
|
43
|
+
export declare function questionUsage(db: DB, question: Pick<QuestionRow, 'id' | 'courseId' | 'categoryId'>): Promise<QuestionUsage[]>;
|
|
44
|
+
export declare function toBankQuestion(db: DB, row: QuestionRow): Promise<BankQuestion>;
|
|
45
|
+
export declare function findQuestion(db: DB, id: string): Promise<QuestionRow>;
|
|
46
|
+
export declare function createQuestion(db: DB, courseId: string, categoryId: string | null | undefined, input: QuestionInput, userId: string | null): Promise<QuestionRow>;
|
|
47
|
+
/** Edits a bank question. Attempts already started keep their own copy. */
|
|
48
|
+
export declare function updateQuestion(db: DB, row: QuestionRow, input: QuestionInput, categoryId?: string | null): Promise<QuestionRow>;
|
|
49
|
+
export declare function duplicateQuestion(db: DB, row: QuestionRow, userId: string | null): Promise<QuestionRow>;
|
|
50
|
+
export declare function moveQuestions(db: DB, courseId: string, ids: string[], categoryId: string): Promise<number>;
|
|
51
|
+
/** Deletes a question that no quiz uses directly. Past attempts keep their snapshot of it. */
|
|
52
|
+
export declare function deleteQuestion(db: DB, row: QuestionRow): Promise<void>;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Question types: validation, storage, grading and what each viewer may see. Pure functions, no database.
|
|
3
|
+
*
|
|
4
|
+
* Attempts never read the question bank after they start: each one keeps a {@link QuestionSnapshot} of its
|
|
5
|
+
* questions (with the order shown to the student), so editing or deleting bank questions never changes a
|
|
6
|
+
* past attempt, its grading or its review.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import type { AttemptAnswer, Question, QuestionResult, QuestionType } from '../../shared/types.js';
|
|
10
|
+
export declare const QUESTION_TYPES: readonly ['single', 'multiple', 'truefalse', 'short', 'numeric', 'essay', 'matching', 'ordering'];
|
|
11
|
+
/** A choice ({ id, text, correct }), an ordering item ({ id, text }, stored in the right order) or a matching pair ({ id, text, answer }). */
|
|
12
|
+
export interface StoredOption {
|
|
13
|
+
id: string;
|
|
14
|
+
text: string;
|
|
15
|
+
correct?: boolean;
|
|
16
|
+
answer?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface QuestionSettings {
|
|
19
|
+
/** essay */
|
|
20
|
+
minWords?: number | null;
|
|
21
|
+
maxWords?: number | null;
|
|
22
|
+
graderNotes?: string | null;
|
|
23
|
+
/** matching: extra wrong answers */
|
|
24
|
+
distractors?: string[];
|
|
25
|
+
}
|
|
26
|
+
/** A question as it was when an attempt started. */
|
|
27
|
+
export interface QuestionSnapshot {
|
|
28
|
+
id: string;
|
|
29
|
+
type: QuestionType;
|
|
30
|
+
prompt: string;
|
|
31
|
+
/** The mark for this question in the attempt. */
|
|
32
|
+
points: number;
|
|
33
|
+
options: StoredOption[];
|
|
34
|
+
acceptedAnswers: string[];
|
|
35
|
+
tolerance: number | null;
|
|
36
|
+
explanation: string | null;
|
|
37
|
+
settings: QuestionSettings;
|
|
38
|
+
/** matching: the answers to choose from, in display order. */
|
|
39
|
+
choices?: Array<{
|
|
40
|
+
id: string;
|
|
41
|
+
text: string;
|
|
42
|
+
}>;
|
|
43
|
+
/** matching: the right choice id for each pair id. */
|
|
44
|
+
key?: Record<string, string>;
|
|
45
|
+
/** ordering: item ids in the order first shown. */
|
|
46
|
+
order?: string[];
|
|
47
|
+
}
|
|
48
|
+
/** The stored columns of a question row (bank questions, or 0.1.x rows in old seed data). */
|
|
49
|
+
export interface QuestionRowLike {
|
|
50
|
+
id: string;
|
|
51
|
+
type: QuestionType;
|
|
52
|
+
prompt: string;
|
|
53
|
+
points: number;
|
|
54
|
+
options: string;
|
|
55
|
+
acceptedAnswers: string;
|
|
56
|
+
tolerance: number | null;
|
|
57
|
+
explanation: string | null;
|
|
58
|
+
settings?: string | null;
|
|
59
|
+
}
|
|
60
|
+
/** An automatic grade: no comment or grader. */
|
|
61
|
+
export type GradeResult = Pick<QuestionResult, 'correct' | 'partial' | 'points' | 'maxPoints' | 'pending'>;
|
|
62
|
+
export declare function normalizeText(value: string): string;
|
|
63
|
+
export declare function wordCount(text: string | undefined | null): number;
|
|
64
|
+
export declare function isChoiceType(type: QuestionType): boolean;
|
|
65
|
+
/** Matching answers are identified by their text, so identical answers become one choice. */
|
|
66
|
+
export declare function matchChoiceId(text: string): string;
|
|
67
|
+
export declare function shuffle<T>(items: readonly T[], random?: () => number): T[];
|
|
68
|
+
/** Neighbouring pairs of `given` that are also neighbours, in the same order, in `correct`. */
|
|
69
|
+
export declare function orderedPairs(correct: readonly string[], given: readonly string[]): number;
|
|
70
|
+
/** The order first shown for an ordering question: shuffled, with no neighbouring pair already right (so it scores 0). */
|
|
71
|
+
export declare function initialOrder(ids: readonly string[], random?: () => number): string[];
|
|
72
|
+
/** Freezes a stored question for an attempt (or a preview), choosing the order its parts are shown in. */
|
|
73
|
+
export declare function snapshotFromRow(row: QuestionRowLike, options?: {
|
|
74
|
+
points?: number;
|
|
75
|
+
random?: () => number;
|
|
76
|
+
}): QuestionSnapshot;
|
|
77
|
+
/** The student's order for an ordering question, or null if it isn't a full arrangement of the items. */
|
|
78
|
+
export declare function validOrder(given: readonly string[] | undefined, ids: readonly string[]): string[] | null;
|
|
79
|
+
/** The answer that counts: an untouched ordering question is answered with the order it was shown in. */
|
|
80
|
+
export declare function effectiveAnswer(q: QuestionSnapshot, answer: AttemptAnswer | undefined): AttemptAnswer | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Grades one answer. Partial credit rules:
|
|
83
|
+
* - multiple: each right choice earns a share of the marks and each wrong choice takes one share away (never below zero);
|
|
84
|
+
* - matching: each item matched to its right answer earns an equal share;
|
|
85
|
+
* - ordering: each neighbouring pair of items that is in the right order earns an equal share (n items have n - 1 pairs);
|
|
86
|
+
* - essay: marked by a teacher; a non-empty answer is `pending` until then.
|
|
87
|
+
*/
|
|
88
|
+
export declare function gradeQuestion(question: QuestionSnapshot | QuestionRowLike, answer: AttemptAnswer | undefined): GradeResult;
|
|
89
|
+
/** What a student sees while answering: no correct answers, no grader notes. */
|
|
90
|
+
export declare function studentQuestion(q: QuestionSnapshot): Question;
|
|
91
|
+
/** Review of a submitted attempt: correct answers and explanations. Grader notes only for staff. */
|
|
92
|
+
export declare function reviewQuestion(q: QuestionSnapshot, staff: boolean): Question;
|
|
93
|
+
/** A bank question as its editors see it. */
|
|
94
|
+
export declare function editorQuestion(row: QuestionRowLike): Question;
|
|
95
|
+
/** Plain-text label for lists: the question's name, or the start of its prompt. */
|
|
96
|
+
export declare function questionLabel(q: {
|
|
97
|
+
name?: string | null;
|
|
98
|
+
prompt: string;
|
|
99
|
+
}, length?: number): string;
|
|
100
|
+
/** A question as editors send it (question bank and quiz editor). */
|
|
101
|
+
export declare const questionInputSchema: z.ZodObject<{
|
|
102
|
+
id: z.ZodOptional<z.ZodString>;
|
|
103
|
+
type: z.ZodEnum<{
|
|
104
|
+
essay: "essay";
|
|
105
|
+
matching: "matching";
|
|
106
|
+
multiple: "multiple";
|
|
107
|
+
numeric: "numeric";
|
|
108
|
+
ordering: "ordering";
|
|
109
|
+
short: "short";
|
|
110
|
+
single: "single";
|
|
111
|
+
truefalse: "truefalse";
|
|
112
|
+
}>;
|
|
113
|
+
name: z.ZodDefault<z.ZodString>;
|
|
114
|
+
prompt: z.ZodString;
|
|
115
|
+
points: z.ZodDefault<z.ZodNumber>;
|
|
116
|
+
options: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
117
|
+
id: z.ZodOptional<z.ZodString>;
|
|
118
|
+
text: z.ZodString;
|
|
119
|
+
correct: z.ZodDefault<z.ZodBoolean>;
|
|
120
|
+
}, z.core.$strip>>>;
|
|
121
|
+
pairs: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
122
|
+
id: z.ZodOptional<z.ZodString>;
|
|
123
|
+
text: z.ZodString;
|
|
124
|
+
answer: z.ZodString;
|
|
125
|
+
}, z.core.$strip>>>;
|
|
126
|
+
distractors: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
127
|
+
acceptedAnswers: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
128
|
+
tolerance: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
129
|
+
explanation: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
130
|
+
minWords: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
131
|
+
maxWords: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
132
|
+
graderNotes: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
133
|
+
}, z.core.$strip>;
|
|
134
|
+
export type QuestionInput = z.output<typeof questionInputSchema>;
|
|
135
|
+
/** The stored columns for a question from editor input. */
|
|
136
|
+
export declare function storedQuestion(q: QuestionInput): {
|
|
137
|
+
type: "essay" | "matching" | "multiple" | "numeric" | "ordering" | "short" | "single" | "truefalse";
|
|
138
|
+
name: string;
|
|
139
|
+
prompt: string;
|
|
140
|
+
points: number;
|
|
141
|
+
options: string;
|
|
142
|
+
acceptedAnswers: string;
|
|
143
|
+
tolerance: number | null;
|
|
144
|
+
explanation: string | null;
|
|
145
|
+
settings: string;
|
|
146
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { QuizSlots } from '../../shared/types.js';
|
|
3
|
+
import type { DB } from '../db/types.js';
|
|
4
|
+
import type { ActivityRow, QuizSlotRow } from '../db/schema.js';
|
|
5
|
+
import { type QuestionSnapshot } from './question-types.js';
|
|
6
|
+
/** Most questions one attempt can have. */
|
|
7
|
+
export declare const MAX_QUIZ_QUESTIONS = 200;
|
|
8
|
+
export declare const slotInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
9
|
+
id: z.ZodOptional<z.ZodString>;
|
|
10
|
+
kind: z.ZodLiteral<"question">;
|
|
11
|
+
questionId: z.ZodString;
|
|
12
|
+
points: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
13
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
14
|
+
id: z.ZodOptional<z.ZodString>;
|
|
15
|
+
kind: z.ZodLiteral<"random">;
|
|
16
|
+
categoryId: z.ZodString;
|
|
17
|
+
questionCount: z.ZodNumber;
|
|
18
|
+
includeSubcategories: z.ZodDefault<z.ZodBoolean>;
|
|
19
|
+
points: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
20
|
+
}, z.core.$strip>], "kind">;
|
|
21
|
+
export type SlotInput = z.output<typeof slotInputSchema>;
|
|
22
|
+
export declare function loadSlots(db: DB, activityId: string): Promise<QuizSlotRow[]>;
|
|
23
|
+
/** Question count and total marks per quiz (quizzes without slots are left out). */
|
|
24
|
+
export declare function quizTotals(db: DB, activityIds: string[]): Promise<Array<{
|
|
25
|
+
activityId: string;
|
|
26
|
+
n: number;
|
|
27
|
+
total: number;
|
|
28
|
+
}>>;
|
|
29
|
+
export declare function describeSlots(db: DB, activity: ActivityRow): Promise<QuizSlots>;
|
|
30
|
+
/** Replaces a quiz's slots. Returns the quiz's new total marks. */
|
|
31
|
+
export declare function saveSlots(db: DB, activity: ActivityRow, inputs: SlotInput[]): Promise<number>;
|
|
32
|
+
/** Chooses the questions for a new attempt, in slot order, with no question twice. */
|
|
33
|
+
export declare function pickQuestions(db: DB, activity: ActivityRow, random?: () => number): Promise<QuestionSnapshot[]>;
|
|
@@ -1,28 +1,59 @@
|
|
|
1
|
-
import type { AttemptAnswer,
|
|
1
|
+
import type { AttemptAnswer, PublicUser, QuestionResult, QuizAttempt, QuizSettings } from '../../shared/types.js';
|
|
2
2
|
import type { AppDeps } from '../context.js';
|
|
3
3
|
import type { DB } from '../db/types.js';
|
|
4
4
|
import type { ActivityRow, CourseRow, QuestionRow, QuizAttemptRow } from '../db/schema.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
correct: boolean;
|
|
9
|
-
}
|
|
5
|
+
import { type QuestionSnapshot, type StoredOption } from './question-types.js';
|
|
6
|
+
export { gradeQuestion, normalizeText } from './question-types.js';
|
|
7
|
+
export type { StoredOption };
|
|
10
8
|
/** Answers saved within this window after the deadline are still accepted (network latency). */
|
|
11
9
|
export declare const ATTEMPT_GRACE_MS = 30000;
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
export declare function
|
|
18
|
-
|
|
10
|
+
/** A question result as stored on the attempt (`gradedBy` is a user id). */
|
|
11
|
+
export interface StoredResult extends Omit<QuestionResult, 'gradedBy'> {
|
|
12
|
+
gradedBy?: string | null;
|
|
13
|
+
}
|
|
14
|
+
/** The quiz's directly added questions, in slot order (what the 0.1.x questions endpoint returns). */
|
|
15
|
+
export declare function loadQuizQuestions(db: DB, activityId: string): Promise<QuestionRow[]>;
|
|
16
|
+
/**
|
|
17
|
+
* The questions of an attempt as they were when it started. Attempts always carry a snapshot (the 0.2.0
|
|
18
|
+
* migration backfilled older ones); if one is missing, the current bank versions are used.
|
|
19
|
+
*/
|
|
20
|
+
export declare function attemptQuestions(db: DB, attempt: QuizAttemptRow): Promise<QuestionSnapshot[]>;
|
|
19
21
|
export declare function isExpired(attempt: QuizAttemptRow): boolean;
|
|
20
22
|
/** Full review (correct answers and explanations) is allowed for this viewer. */
|
|
21
23
|
export declare function canReview(settings: QuizSettings, activity: ActivityRow, isManager: boolean): boolean;
|
|
22
24
|
export declare function startAttempt(deps: Pick<AppDeps, 'db' | 'events'>, activity: ActivityRow, userId: string, options: {
|
|
23
25
|
isManager: boolean;
|
|
24
26
|
}): Promise<QuizAttemptRow>;
|
|
27
|
+
/**
|
|
28
|
+
* Submits an attempt and grades it from its snapshot. Attempts with essay answers become `needs_grading`:
|
|
29
|
+
* their score stays pending and no grade is recorded until every essay has a mark.
|
|
30
|
+
*/
|
|
25
31
|
export declare function finishAttempt(deps: Pick<AppDeps, 'db' | 'events'>, attempt: QuizAttemptRow, activity: ActivityRow, answers?: Record<string, AttemptAnswer>): Promise<QuizAttemptRow>;
|
|
26
32
|
/** Recomputes a student's quiz grade from their finished attempts using the quiz's grading method. */
|
|
27
33
|
export declare function updateQuizGrade(deps: Pick<AppDeps, 'db' | 'events'>, activity: ActivityRow, userId: string): Promise<void>;
|
|
28
|
-
|
|
34
|
+
/** Recomputes every student's grade for a quiz (after its maximum changes), writing only grades that change. */
|
|
35
|
+
export declare function regradeQuiz(deps: Pick<AppDeps, 'db' | 'events'>, activity: ActivityRow): Promise<void>;
|
|
36
|
+
/** Students' attempts at a quiz that wait for essays to be marked. */
|
|
37
|
+
export declare function countNeedsGrading(db: DB, activityId: string): Promise<number>;
|
|
38
|
+
/**
|
|
39
|
+
* Marks one essay answer. When the last essay of an attempt gets its mark, the score becomes final, the
|
|
40
|
+
* grade is recorded (`grade.updated`) and the student is notified. Marks can be changed later.
|
|
41
|
+
*/
|
|
42
|
+
export declare function gradeEssay(deps: Pick<AppDeps, 'db' | 'events'>, input: {
|
|
43
|
+
attemptId: string;
|
|
44
|
+
activity: ActivityRow;
|
|
45
|
+
course: CourseRow;
|
|
46
|
+
questionId: string;
|
|
47
|
+
points: number;
|
|
48
|
+
comment: string | null;
|
|
49
|
+
graderId: string;
|
|
50
|
+
}): Promise<QuizAttemptRow>;
|
|
51
|
+
export declare function toAttemptDto(attempt: QuizAttemptRow, activity: ActivityRow, course: CourseRow, questions: QuestionSnapshot[], options: {
|
|
52
|
+
review: boolean;
|
|
53
|
+
staff: boolean;
|
|
54
|
+
canGrade: boolean;
|
|
55
|
+
users: Map<string, PublicUser>;
|
|
56
|
+
owner?: PublicUser;
|
|
57
|
+
}): QuizAttempt;
|
|
58
|
+
/** Users who marked answers in an attempt by hand. */
|
|
59
|
+
export declare function graderIds(attempt: QuizAttemptRow): string[];
|