Skip to content

Commit

Permalink
Merge pull request #299 from nwplus/daniel/points-column
Browse files Browse the repository at this point in the history
Sum up points for each hacker's event attendance in firebase queries
  • Loading branch information
DonaldKLee authored Jan 16, 2025
2 parents f286d69 + 80cec94 commit 0aea362
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 4 additions & 5 deletions utility/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,10 @@ export const getHackerInfo = async (callback, hackathon, collection) => {
.doc(hackathon)
.collection(collection)
.onSnapshot(snap => {
callback(
snap.docs.map(doc => {
return orderObj(flattenObj(filterHackerInfoFields(doc.data(), collection)))
})
)
const hackerInfoPromises = snap.docs.map(async doc => {
return orderObj(flattenObj(await filterHackerInfoFields(db, doc.data(), hackathon, collection)))
})
Promise.all(hackerInfoPromises).then(callback)
})
return res
}
Expand Down
9 changes: 8 additions & 1 deletion utility/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const createStringFromSelection = (selection, other = '') => {
}

// Specifically for hacker info page - fixes/removes certain fields for table display
export const filterHackerInfoFields = (obj, collection) => {
// Take `db` as a parameter to avoid circular dependency with firebase.js
export const filterHackerInfoFields = async (db, obj, hackathon, collection) => {
let newObj = {}
if (collection === 'Applicants') {
delete obj.questionnaire?.eventsAttended
Expand Down Expand Up @@ -144,6 +145,12 @@ export const filterHackerInfoFields = (obj, collection) => {
newObj.longAnswers3 = obj.skills?.longAnswers3 || false

newObj.attendedEvents = obj.dayOf?.events?.map(e => e.eventName).join(', ') ?? ''

const dayOfDocsPromises = obj.dayOf?.events?.map(e =>
db.collection('Hackathons').doc(hackathon).collection('DayOf').doc(e.eventId).get()
)
const dayOfDocs = await Promise.all(dayOfDocsPromises ?? [])
newObj.points = dayOfDocs.reduce((acc, curr) => acc + Number(curr.data().points ?? 0), 0)
} else if (collection === 'Projects') {
newObj = { ...obj }
delete newObj.grades
Expand Down

0 comments on commit 0aea362

Please sign in to comment.