From f31aa801021c9a86a663c51ec9bf0d7ac6d83a10 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 8 Jul 2020 16:32:22 +0100 Subject: [PATCH] fixed a bug that would cause the pb object to not be saved correctly --- functions/index.js | 6 +++++- public/js/db.js | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/functions/index.js b/functions/index.js index 3a4944847..a01c56886 100644 --- a/functions/index.js +++ b/functions/index.js @@ -267,6 +267,9 @@ function checkIfPB(uid, obj) { let toUpdate = false; let found = false; try { + if (pbs[obj.mode][obj.mode2] === undefined) { + pbs[obj.mode][obj.mode2] = []; + } pbs[obj.mode][obj.mode2].forEach((pb) => { if ( pb.punctuation === obj.punctuation && @@ -356,7 +359,8 @@ exports.testCompleted = functions.https.onCall((request, response) => { return -1; } - db.collection("users") + return db + .collection("users") .doc(request.uid) .get() .then((ret) => { diff --git a/public/js/db.js b/public/js/db.js index 2584a3695..653a2a325 100644 --- a/public/js/db.js +++ b/public/js/db.js @@ -142,6 +142,9 @@ async function db_saveLocalPB( function cont() { try { let found = false; + if (dbSnapshot.personalBests[mode][mode2] === undefined) { + dbSnapshot.personalBests[mode][mode2] = []; + } dbSnapshot.personalBests[mode][mode2].forEach((pb) => { if ( pb.punctuation == punctuation &&