Skip to content

Commit

Permalink
Merge pull request #4 from chrismbirmingham/challengeLeaderboard
Browse files Browse the repository at this point in the history
Support getting challenge completion data for all users
  • Loading branch information
tcorbly authored Nov 5, 2024
2 parents 17baf6f + 8c5a238 commit f909c8a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f909c8a

Please sign in to comment.