Skip to content

Commit

Permalink
Merge pull request #638 from nwplus/peer-judging-hotfix
Browse files Browse the repository at this point in the history
hopefully we don't need this
  • Loading branch information
DonaldKLee authored Nov 10, 2024
2 parents 96d2ac6 + 4d5f389 commit 0ace239
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/pages/Judging/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@ const StyledJudgingCard = styled(JudgingCard)`
const getProjects = async (userId, projectId, dbHackathonName) => {
const getAndAssignProjects = async () => {
try {
return db.runTransaction(async transaction => {
const projectDocs = await transaction.get(
projectsRef(dbHackathonName)
.where('draftStatus', '==', 'public')
.orderBy('countAssigned')
.limit(PROJECTS_TO_JUDGE_COUNT + 1) // get an extra in case we got our own project
)
const projectSnapshot = await projectsRef(dbHackathonName)
.where('draftStatus', '==', 'public')
.orderBy('countAssigned')
.limit(PROJECTS_TO_JUDGE_COUNT + 1)
.get()

let projectIds = projectDocs.docs.map(project => project.id)
projectIds = projectIds.filter(id => id !== projectId)
if (projectIds.length > PROJECTS_TO_JUDGE_COUNT) {
projectIds.pop()
}
let projectIds = projectSnapshot.docs.map(project => project.id)
projectIds = projectIds.filter(id => id !== projectId)
if (projectIds.length > PROJECTS_TO_JUDGE_COUNT) {
projectIds.pop()
}

// increment assigned counters
await db.runTransaction(async transaction => {
projectIds.forEach(projectId => {
const projectRef = projectsRef(dbHackathonName).doc(projectId)
transaction.update(projectRef, {
Expand All @@ -43,8 +41,9 @@ const getProjects = async (userId, projectId, dbHackathonName) => {
transaction.update(applicantRef, {
projectsAssigned: projectIds,
})
return projectIds
})

return projectIds
} catch (error) {
console.error('Error assigning projects:', error)
}
Expand Down

0 comments on commit 0ace239

Please sign in to comment.