UNPKG

@gmetrixr/rjson

Version:
41 lines (40 loc) 2.38 kB
import { r, rtp, RT, en } from "../../../r"; /** * Flattens the Quiz property quiz_instructions * Older Structure: * /** * export interface QuizInstruction { * heading: { name: string, placeholder: string, value: string }, -----> heading * correct_score: { name: string, placeholder: string, value: number }, ------> quiz_correct_score * wrong_score: { name: string, placeholder: string, value: number }, ------> quiz_wrong_score * pass_mark: { name: string, placeholder: string, value: number } ------> quiz_passing_score * } * * [ElementProperty.quiz_starting_instructions]: {}, * [ElementProperty.quiz_passing_score]: {}, * [ElementProperty.quiz_correct_score]: {}, * [ElementProperty.quiz_wrong_score]: {}, */ class Migration { execute(projectJson) { const pJson = projectJson; const projectF = r.record(pJson); projectF.getRecords(RT.scene).forEach(scene => { var _a, _b, _c, _d; const sceneF = r.record(scene); const quizElements = sceneF.getAllDeepChildrenWithFilter(RT.element, (e) => e.props.element_type === en.ElementType.quiz); for (const quizElement of quizElements) { const quiz_instructions = quizElement.props.quiz_instructions; quizElement.props.quiz_starting_instructions = (_a = quiz_instructions === null || quiz_instructions === void 0 ? void 0 : quiz_instructions.heading) === null || _a === void 0 ? void 0 : _a.value; quizElement.props.quiz_passing_score = (_b = quiz_instructions === null || quiz_instructions === void 0 ? void 0 : quiz_instructions.pass_mark) === null || _b === void 0 ? void 0 : _b.value; quizElement.props.quiz_correct_score = (_c = quiz_instructions === null || quiz_instructions === void 0 ? void 0 : quiz_instructions.correct_score) === null || _c === void 0 ? void 0 : _c.value; quizElement.props.quiz_wrong_score = (_d = quiz_instructions === null || quiz_instructions === void 0 ? void 0 : quiz_instructions.wrong_score) === null || _d === void 0 ? void 0 : _d.value; delete quizElement.props.quiz_instructions; delete quizElement.props.quiz_elements; } }); projectF.set(rtp.project.version, 122); } } const migration = new Migration(); export default migration;