fix(exercise): persist completion policy and improve dev build workflow (#754)
* fix(exercise): persist completion policy and pass threshold on save buildExerciseUpdateFields accepted completionPolicy and passThreshold in the validation schema but never mapped them to the database update, so exercise settings appeared to save while reverting on refresh. Co-authored-by: Rotimi Best <[email protected]> * fix(db): build workspace deps before compiling @cio/db imports @cio/utils/notifications, which only exists after @cio/utils is built. Building db in isolation failed when utils dist was missing or stale. - Add a db prebuild step for question-types, utils, and email - Clean dist and tsbuildinfo before utils and email builds so incremental tsc cannot skip emission after dist was removed Co-authored-by: Rotimi Best <[email protected]> * chore(dev): build api workspace deps before api:dev Run turbo build for @cio/api and @cio/jobs-worker dependencies before starting the dev servers, so missing dist/ folders do not break startup. Co-authored-by: Rotimi Best <[email protected]> * feat(course): improve exercise progression grading UX --------- Co-authored-by: Rotimi Best <[email protected]>
This commit is contained in:
co-authored by
Rotimi Best
parent
fdc19aac41
commit
bfafc685e0
@@ -18,3 +18,4 @@ export * from './renderer-registry';
|
||||
export * from './textarea-validation';
|
||||
export * from './star-rating-settings';
|
||||
export * from './video-recording-settings';
|
||||
export * from './true-false-answer-key';
|
||||
|
||||
@@ -5,6 +5,7 @@ import { getQuestionTypeById } from './question-type-lookup';
|
||||
import { QUESTION_TYPE_ID_TO_KEY } from './question-type-registry';
|
||||
import { supportsPartialCredit } from './question-type-capabilities';
|
||||
import { getStarRatingMaxFromSettings, isValidStarRatingValue } from './star-rating-settings';
|
||||
import { resolveTrueFalseCorrectValue } from './true-false-answer-key';
|
||||
|
||||
export type DbQuestionForScoring = {
|
||||
id: number;
|
||||
@@ -112,20 +113,7 @@ function scoreTrueFalse(
|
||||
answer: Extract<AnswerData, { type: 'TRUE_FALSE' }>,
|
||||
maxPoints: number
|
||||
): number {
|
||||
const opts = question.options ?? [];
|
||||
const trueOpt = opts.find((o) => normalizeText(o.label) === 'true');
|
||||
const falseOpt = opts.find((o) => normalizeText(o.label) === 'false');
|
||||
const correctFromSettings = question.settings?.correctValue;
|
||||
let correctIsTrue: boolean;
|
||||
if (typeof correctFromSettings === 'boolean') {
|
||||
correctIsTrue = correctFromSettings;
|
||||
} else if (trueOpt?.isCorrect) {
|
||||
correctIsTrue = true;
|
||||
} else if (falseOpt?.isCorrect) {
|
||||
correctIsTrue = false;
|
||||
} else {
|
||||
correctIsTrue = true;
|
||||
}
|
||||
const correctIsTrue = resolveTrueFalseCorrectValue(question.settings, question.options);
|
||||
|
||||
return answer.value === correctIsTrue ? maxPoints : 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
export type TrueFalseAnswerOption = {
|
||||
label?: string | null;
|
||||
value?: string | number | boolean | null;
|
||||
isCorrect?: boolean;
|
||||
deletedAt?: unknown;
|
||||
};
|
||||
|
||||
function normalizeBooleanText(value: unknown): string {
|
||||
return String(value ?? '')
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
export function getTrueFalseOptionValue(option: TrueFalseAnswerOption): boolean | undefined {
|
||||
const normalizedValue = normalizeBooleanText(option.value);
|
||||
if (normalizedValue === 'true' || normalizedValue === '1') return true;
|
||||
if (normalizedValue === 'false' || normalizedValue === '0') return false;
|
||||
|
||||
const normalizedLabel = normalizeBooleanText(option.label);
|
||||
if (normalizedLabel === 'true' || normalizedLabel === '1') return true;
|
||||
if (normalizedLabel === 'false' || normalizedLabel === '0') return false;
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveTrueFalseCorrectValue(
|
||||
settings: Record<string, unknown> | undefined,
|
||||
options: TrueFalseAnswerOption[] | undefined,
|
||||
fallback = true
|
||||
): boolean {
|
||||
if (typeof settings?.correctValue === 'boolean') return settings.correctValue;
|
||||
|
||||
const correctOption = options?.find((option) => !option.deletedAt && option.isCorrect);
|
||||
const correctValue = correctOption ? getTrueFalseOptionValue(correctOption) : undefined;
|
||||
|
||||
return typeof correctValue === 'boolean' ? correctValue : fallback;
|
||||
}
|
||||
|
||||
export function syncTrueFalseOptions<T extends TrueFalseAnswerOption>(
|
||||
options: T[] | undefined,
|
||||
correctValue: boolean
|
||||
): T[] {
|
||||
return (options ?? []).map((option) => {
|
||||
const optionValue = getTrueFalseOptionValue(option);
|
||||
if (typeof optionValue !== 'boolean') return option;
|
||||
|
||||
return { ...option, isCorrect: optionValue === correctValue };
|
||||
});
|
||||
}
|
||||
|
||||
export function getCanonicalTrueFalseSettings(
|
||||
settings: Record<string, unknown> | undefined,
|
||||
options: TrueFalseAnswerOption[] | undefined
|
||||
): Record<string, unknown> {
|
||||
return {
|
||||
...(settings ?? {}),
|
||||
correctValue: resolveTrueFalseCorrectValue(settings, options)
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user