Store set IDs in completed progress records
This commit is contained in:
@@ -426,11 +426,14 @@ exports.processAnswer = functions.https.onCall((data, context) => {
|
|||||||
return transaction.get(progressDocId).then((progressDoc) => {
|
return transaction.get(progressDocId).then((progressDoc) => {
|
||||||
if (!progressDoc.exists) {
|
if (!progressDoc.exists) {
|
||||||
throw new functions.https.HttpsError("not-found", "Progress record " + progressId + " doesn't exist")
|
throw new functions.https.HttpsError("not-found", "Progress record " + progressId + " doesn't exist")
|
||||||
} else if (uid !== progressDoc.data().uid) {
|
}
|
||||||
|
if (uid !== progressDoc.data().uid) {
|
||||||
throw new functions.https.HttpsError("permission-denied", "Wrong user's progress");
|
throw new functions.https.HttpsError("permission-denied", "Wrong user's progress");
|
||||||
} else if (progressDoc.data().progress >= progressDoc.data().questions.length || (progressDoc.data().mode === "lives" && progressDoc.data().lives <= 0)) {
|
}
|
||||||
|
if (progressDoc.data().progress >= progressDoc.data().questions.length || (progressDoc.data().mode === "lives" && progressDoc.data().lives <= 0)) {
|
||||||
throw new functions.https.HttpsError("permission-denied", "Progress already completed")
|
throw new functions.https.HttpsError("permission-denied", "Progress already completed")
|
||||||
} else {
|
}
|
||||||
|
|
||||||
const currentIndex = progressDoc.data().progress;
|
const currentIndex = progressDoc.data().progress;
|
||||||
const currentVocab = progressDoc.data().questions[currentIndex];
|
const currentVocab = progressDoc.data().questions[currentIndex];
|
||||||
|
|
||||||
@@ -471,7 +474,6 @@ exports.processAnswer = functions.https.onCall((data, context) => {
|
|||||||
const levDistance = levenshtein(answer, cleansedInputAnswer);
|
const levDistance = levenshtein(answer, cleansedInputAnswer);
|
||||||
if (levDistance <= 1 ||
|
if (levDistance <= 1 ||
|
||||||
answer.length > 5 && levDistance <= 3 ||
|
answer.length > 5 && levDistance <= 3 ||
|
||||||
answer.length > 10 && levDistance <= 4 ||
|
|
||||||
cleansedInputAnswer.includes(answer)) {
|
cleansedInputAnswer.includes(answer)) {
|
||||||
docData.typo = true;
|
docData.typo = true;
|
||||||
transaction.set(progressDocId, docData);
|
transaction.set(progressDocId, docData);
|
||||||
@@ -571,6 +573,7 @@ exports.processAnswer = functions.https.onCall((data, context) => {
|
|||||||
transaction.set(completedProgressDocId, {
|
transaction.set(completedProgressDocId, {
|
||||||
attempts: attempts,
|
attempts: attempts,
|
||||||
total_percentage: totalPercentage,
|
total_percentage: totalPercentage,
|
||||||
|
setIds: progressDoc.data().setIds,
|
||||||
});
|
});
|
||||||
returnData.averagePercentage = (totalPercentage / attempts).toFixed(2);
|
returnData.averagePercentage = (totalPercentage / attempts).toFixed(2);
|
||||||
transaction.set(progressDocId, docData);
|
transaction.set(progressDocId, docData);
|
||||||
|
|||||||
Reference in New Issue
Block a user