diff --git a/readme.md b/readme.md index 10b29a2..24913ad 100644 --- a/readme.md +++ b/readme.md @@ -45,7 +45,7 @@ yarn build ## Execution -Redis server must be running. +Redis server must be running. (Check with redis-cli) ```sh FIREBASE_SERVICE_ACCOUNT_KEY_FILE=service_account_key.json FIREBASE_DATABASE_URL=https://kipr-321905-default-rtdb.firebaseio.com yarn start diff --git a/src/db.ts b/src/db.ts index 038d934..9ea21c7 100644 --- a/src/db.ts +++ b/src/db.ts @@ -160,6 +160,39 @@ class Db { message: `Collection "${collection}" is invalid.`, }; + + if (collection === CHALLENGE_COMPLETION_COLLECTION) { + const challengeRef = firestore.collectionGroup('challenge_completion') + const challengeSnapshot = await challengeRef.get(); + const groupData = {}; + const userData = {}; + challengeSnapshot.forEach((doc) => { + const id = doc.ref.parent.parent.id; + const data = doc.data(); + if (author.id !== id) { + if (groupData[id]) { + groupData[id][doc.id] = data; + return; + } + groupData[id] = {[doc.id]: doc.data()}; + } else { + if (userData[id]) { + userData[id][doc.id] = data; + return; + } + userData[id] = {[doc.id]: doc.data()}; + } + }); + const values = { + groupData, + userData, + }; + return { + type: 'success', + values: values, + }; + } + const docs = await firestore .collection(collection) .where('author.id', '==', author.id)