diff --git a/src/controllers/colleges.js b/src/controllers/colleges.js index 8108227..3e3416e 100644 --- a/src/controllers/colleges.js +++ b/src/controllers/colleges.js @@ -330,6 +330,54 @@ 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, @@ -337,5 +385,6 @@ module.exports = { getParticipants, getTeams, update, - getAllEventsRanking + getAllEventsRanking, + getPublishedEventsRanking, }; diff --git a/src/routes/colleges.js b/src/routes/colleges.js index 6f9b542..601cf28 100644 --- a/src/routes/colleges.js +++ b/src/routes/colleges.js @@ -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);