Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing #107

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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