@quesmed/types 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils/commonFunctions.js +7 -3
package/package.json
CHANGED
package/utils/commonFunctions.js
CHANGED
|
@@ -61,6 +61,7 @@ function formatPrescribeAnswer(obj) {
|
|
|
61
61
|
}
|
|
62
62
|
return obj;
|
|
63
63
|
}
|
|
64
|
+
const answerRegex = /answer/gi;
|
|
64
65
|
function correctMark(mark) {
|
|
65
66
|
const data = {
|
|
66
67
|
correct: false,
|
|
@@ -70,7 +71,10 @@ function correctMark(mark) {
|
|
|
70
71
|
if (!mark || !mark.mark) {
|
|
71
72
|
return data;
|
|
72
73
|
}
|
|
73
|
-
const
|
|
74
|
+
const qKeys = Object.keys(mark.question);
|
|
75
|
+
const answerKey = qKeys.find((k) => answerRegex.exec(k)) || 'answer';
|
|
76
|
+
const answer = mark.question[answerKey];
|
|
77
|
+
const flatAnswer = answer[0];
|
|
74
78
|
const flatAttempt = mark.mark[0];
|
|
75
79
|
if (models_1.EQuestionType.SINGLE_BEST_ANSWER === mark.question.typeId) {
|
|
76
80
|
const answer = flatAnswer;
|
|
@@ -93,7 +97,7 @@ function correctMark(mark) {
|
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
else if (models_1.EQuestionType.MULTIPLE_ANSWERS === mark.question.typeId) {
|
|
96
|
-
const [answerA, answerB] =
|
|
100
|
+
const [answerA, answerB] = answer.map((x) => x.sort());
|
|
97
101
|
const [attemptA, attemptB] = mark.mark.map((x) => x.sort());
|
|
98
102
|
if (answerA.length !== attemptA.length || answerB.length !== attemptB.length) {
|
|
99
103
|
data.incorrect = true;
|
|
@@ -106,7 +110,7 @@ function correctMark(mark) {
|
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
112
|
else if (models_1.EQuestionType.PRESCRIPTION_ANSWER === mark.question.typeId) {
|
|
109
|
-
const answers =
|
|
113
|
+
const answers = answer.map(formatPrescribeAnswer);
|
|
110
114
|
const attempt = formatPrescribeAnswer(flatAttempt);
|
|
111
115
|
let foundCorrect = false;
|
|
112
116
|
let index = 0;
|