frontPanel/src/model/quiz/quiz.ts

136 lines
4.0 KiB
TypeScript
Raw Normal View History

2023-11-13 18:04:51 +00:00
import { QuizConfig, defaultQuizConfig } from "@model/quizSettings";
export interface Quiz {
/** Id of created quiz */
2023-11-02 16:45:28 +00:00
id: number;
2023-11-13 18:04:51 +00:00
/** string id for customers */
2023-11-02 16:45:28 +00:00
qid: string;
2023-11-13 18:04:51 +00:00
/** true if quiz deleted */
2023-11-02 16:45:28 +00:00
deleted: boolean;
2023-11-13 18:04:51 +00:00
/** true if quiz archived */
2023-11-02 16:45:28 +00:00
archived: boolean;
2023-11-13 18:04:51 +00:00
/** set true for save deviceId */
2023-11-02 16:45:28 +00:00
fingerprinting: boolean;
2023-11-13 18:04:51 +00:00
/** set true for allow user to repeat quiz */
2023-11-02 16:45:28 +00:00
repeatable: boolean;
2023-11-13 18:04:51 +00:00
/** set true for save statistic of incomplete quiz passing */
2023-11-02 16:45:28 +00:00
note_prevented: boolean;
2023-11-13 18:04:51 +00:00
/** set true for mail notification for each quiz passing */
2023-11-02 16:45:28 +00:00
mail_notifications: boolean;
2023-11-13 18:04:51 +00:00
/** set true for save statistics only for unique quiz passing */
2023-11-02 16:45:28 +00:00
unique_answers: boolean;
2023-11-13 18:04:51 +00:00
/** name of quiz. max 280 length */
2023-11-02 16:45:28 +00:00
name: string;
2023-11-13 18:04:51 +00:00
/** description of quiz */
2023-11-02 16:45:28 +00:00
description: string;
2023-11-13 18:04:51 +00:00
/** quiz config*/
config: QuizConfig;
/** status of quiz. allow only '', 'draft', 'template', 'stop', 'start' */
status: string;
/** limit is count of max quiz passing */
limit: number;
/** last time when quiz is valid. timestamp in seconds */
due_to: number;
/** seconds to pass quiz */
time_of_passing: number;
/** true if it is allowed for pause quiz */
pausable: boolean;
/** version of quiz */
version: number;
/** version comment to version of quiz */
version_comment: string;
/** array of previous versions of quiz */
parent_ids: number[];
created_at: string;
updated_at: string;
/** count of questions */
question_cnt: number;
/** count passings */
passed_count: number;
/** average time of passing */
average_time: number;
/** set true if squiz realize group functionality */
super: boolean;
/** group of new quiz */
group_id: number;
}
2023-11-14 16:43:21 +00:00
/** Type that comes from server */
2023-11-13 18:04:51 +00:00
export interface RawQuiz {
/** Id of created quiz */
id: number;
/** string id for customers */
qid: string;
/** true if quiz deleted */
deleted: boolean;
/** true if quiz archived */
archived: boolean;
/** set true for save deviceId */
fingerprinting: boolean;
/** set true for allow user to repeat quiz */
repeatable: boolean;
/** set true for save statistic of incomplete quiz passing */
note_prevented: boolean;
/** set true for mail notification for each quiz passing */
mail_notifications: boolean;
/** set true for save statistics only for unique quiz passing */
unique_answers: boolean;
/** name of quiz. max 280 length */
name: string;
/** description of quiz */
description: string;
/** config of quiz. serialized json for rules of quiz flow */
2023-11-02 16:45:28 +00:00
config: string;
2023-11-13 18:04:51 +00:00
/** status of quiz. allow only '', 'draft', 'template', 'stop', 'start' */
2023-11-02 16:45:28 +00:00
status: string;
2023-11-13 18:04:51 +00:00
/** limit is count of max quiz passing */
2023-11-02 16:45:28 +00:00
limit: number;
2023-11-13 18:04:51 +00:00
/** last time when quiz is valid. timestamp in seconds */
2023-11-02 16:45:28 +00:00
due_to: number;
2023-11-13 18:04:51 +00:00
/** seconds to pass quiz */
2023-11-02 16:45:28 +00:00
time_of_passing: number;
2023-11-13 18:04:51 +00:00
/** true if it is allowed for pause quiz */
2023-11-02 16:45:28 +00:00
pausable: boolean;
2023-11-13 18:04:51 +00:00
/** version of quiz */
2023-11-02 16:45:28 +00:00
version: number;
2023-11-13 18:04:51 +00:00
/** version comment to version of quiz */
2023-11-02 16:45:28 +00:00
version_comment: string;
2023-11-13 18:04:51 +00:00
/** array of previous versions of quiz */
2023-11-02 16:45:28 +00:00
parent_ids: number[];
created_at: string;
updated_at: string;
2023-11-13 18:04:51 +00:00
/** count of questions */
2023-11-02 16:45:28 +00:00
question_cnt: number;
2023-11-13 18:04:51 +00:00
/** count passings */
2023-11-02 16:45:28 +00:00
passed_count: number;
2023-11-13 18:04:51 +00:00
/** average time of passing */
2023-11-02 16:45:28 +00:00
average_time: number;
2023-11-13 18:04:51 +00:00
/** set true if squiz realize group functionality */
2023-11-02 16:45:28 +00:00
super: boolean;
2023-11-13 18:04:51 +00:00
/** group of new quiz */
2023-11-02 16:45:28 +00:00
group_id: number;
}
2023-11-13 18:04:51 +00:00
export function quizToRawQuiz(quiz: Quiz): RawQuiz {
return {
...quiz,
config: JSON.stringify(quiz.config),
};
}
export function rawQuizToQuiz(rawQuiz: RawQuiz): Quiz {
let config = defaultQuizConfig;
try {
config = JSON.parse(rawQuiz.config);
} catch (error) {
console.warn("Cannot parse quiz config from string, using default config", error);
}
return {
...rawQuiz,
config,
};
}