Class share links: visitors choose the exam for a generated set
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 24s
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 24s
On a class link with exams, the visitor's Generate dialog asks which exam the set is for (opening on the latest exam with materials, with "Not in an exam" when there is loose material). Only that exam's class materials are offered, and the set is saved into it. The server requires the choice and refuses materials from another exam. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
76112cb4ae
commit
d8df5edf30
4 changed files with 98 additions and 9 deletions
|
|
@ -496,7 +496,12 @@ export function publicRoutes(app: AppContext): Hono {
|
|||
kind: z.enum(['quiz', 'deck']),
|
||||
count: z.number().int().min(1).max(SHARE_DECK_MAX).optional(),
|
||||
difficulty: z.enum(['easy', 'medium', 'hard', 'mixed']).default('mixed'),
|
||||
/** Class materials to use; empty or absent: all of them. */
|
||||
/**
|
||||
* Class links: the exam the set is for (null: not in an exam). Required when the class has
|
||||
* exams. The set uses only that exam's materials and is saved into it.
|
||||
*/
|
||||
examId: z.string().max(64).nullable().optional(),
|
||||
/** Class materials to use, from the chosen exam; empty or absent: all of them. */
|
||||
documentIds: z.array(z.string().max(64)).max(50).optional(),
|
||||
/** Quizzes: add medication math questions, whatever the material covers. */
|
||||
math: z.boolean().optional(),
|
||||
|
|
@ -512,8 +517,18 @@ export function publicRoutes(app: AppContext): Hono {
|
|||
const body = await readBody(c, generateSchema);
|
||||
if (share.kind !== 'class' && share.kind !== 'folder') throw gone();
|
||||
requireAi(c, share, 'generate');
|
||||
const docs = collectionItems(app, share).filter((i) => i.kind === 'document');
|
||||
if (docs.length === 0) throw new HttpError(400, 'no_materials', 'There are no class materials on this link to generate from.');
|
||||
// Which exam the set is for: an exam link's own, or the visitor's choice on a class link.
|
||||
let examId: string | null = share.kind === 'folder' ? share.target_id : null;
|
||||
if (share.kind === 'class') {
|
||||
const exams = db.all<{ id: string }>('SELECT id FROM folders WHERE class_id = ?', share.target_id);
|
||||
if (body.examId === undefined && exams.length > 0) throw new HttpError(400, 'exam_required', 'Choose which exam this is for.');
|
||||
if (body.examId && !exams.some((e) => e.id === body.examId)) throw gone();
|
||||
examId = body.examId ?? null;
|
||||
}
|
||||
const docs = collectionItems(app, share).filter(
|
||||
(i) => i.kind === 'document' && (share.kind === 'folder' || (examId ? i.folderId === examId : !i.folderId || !db.get('SELECT 1 FROM folders WHERE id = ?', i.folderId))),
|
||||
);
|
||||
if (docs.length === 0) throw new HttpError(400, 'no_materials', examId || share.kind === 'folder' ? 'This exam has no class materials to generate from.' : 'There are no class materials outside the exams to generate from.');
|
||||
const chosen = body.documentIds?.length ? body.documentIds : docs.map((d) => d.id);
|
||||
if (chosen.some((id) => !docs.some((d) => d.id === id))) throw gone();
|
||||
const usage = generateUsage(app, share)[body.kind];
|
||||
|
|
@ -529,7 +544,7 @@ export function publicRoutes(app: AppContext): Hono {
|
|||
{
|
||||
kind: body.kind,
|
||||
classId: sharedClassId(share),
|
||||
folderId: share.kind === 'folder' ? share.target_id : null,
|
||||
folderId: examId,
|
||||
source: { documentIds: chosen },
|
||||
count,
|
||||
difficulty: body.difficulty,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue