37 lines
994 B
TypeScript
37 lines
994 B
TypeScript
// mask the full exercise object to only the part that the client needs to see
|
|
// in order to present it to the user (so the user can't just peek into network
|
|
// transactions to see what the correct answer is)
|
|
|
|
import type { Exercise } from "materialdb/db";
|
|
import { ExerciseInstance } from "$lib/db";
|
|
import type { LoginStatus } from "$lib/auth";
|
|
import { ExerciseStyle } from ".";
|
|
|
|
export class ExerciseInfo {
|
|
public style: string;
|
|
public props: any;
|
|
}
|
|
|
|
export async function createInstance(loginStatus: LoginStatus, exercise: Exercise): Promise<ExerciseInfo> {
|
|
let props;
|
|
switch (exercise.style) {
|
|
case ExerciseStyle.GradedProgram:
|
|
break;
|
|
case ExerciseStyle.MultipleChoice:
|
|
break;
|
|
}
|
|
|
|
let instance = new ExerciseInstance({
|
|
user_id: loginStatus.user_id,
|
|
exercise_name: exercise.name,
|
|
props,
|
|
});
|
|
instance.save();
|
|
|
|
let info = new ExerciseInfo();
|
|
info.style = exercise.style;
|
|
info.props = props;
|
|
console.log("info", info);
|
|
return info;
|
|
}
|