Skip to content

Commit

Permalink
Added publishedEventsRank
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajoy10 committed Mar 31, 2024
1 parent c984e97 commit b55e4d5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/controllers/colleges.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,61 @@ const getAllEventsRanking = async (req, res) => {

}

const getPublishedEventsRanking = async (req, res) => {
try {
let events = await EventModel.find();
let response = [];
//get the latest leaderboard of all events
await Promise.all(events.map(async event => {
try {
//if event doesn't have any rounds, move to next event.
if (event.rounds.length == 0)
return;
//get last round id
let roundId = event.rounds[event.rounds.length - 1];
const round = await RoundModel.findOne({ _id: roundId });
if(!round.published)
{
response.push({
event,
ranks:[],
});
return;
}
// console.log(event, roundId);
let leaderboard = await getRoundLeaderboard(roundId);
let ranks = leaderboard.filter(item => item.slot.college._id == req.params.college);
response.push({
event,
ranks,
});
} catch (err) {
console.log(err);
}
}))
return res.json({
status: 200,
message: "Success",
data: response,
});
} catch (error) {
console.log(error);
return res.json({
status: 500,
message: "Server Error",
data: error,
});
}

}

module.exports = {
create,
get,
getAll,
getParticipants,
getTeams,
update,
getAllEventsRanking
getAllEventsRanking,
getPublishedEventsRanking,
};
2 changes: 2 additions & 0 deletions src/routes/colleges.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ router.get("/:college/participants", Colleges.getParticipants);
router.get("/:college/teams", Colleges.getTeams);
//return ranking for all events
router.get("/:college/rankings", Colleges.getAllEventsRanking);
router.get("/:college/public-rankings", Colleges.getPublishedEventsRanking);


// Create a new college
router.post("/", Colleges.create);
Expand Down

0 comments on commit b55e4d5

Please sign in to comment.