diff --git a/src/admin/routes/api.js b/src/admin/routes/api.js index 1bf2ab78..5cc90d93 100644 --- a/src/admin/routes/api.js +++ b/src/admin/routes/api.js @@ -89,19 +89,18 @@ router.post("/setMatch", (req,res) => { router.get("/matches", async (req,res) => { - let manualSchedule = getManualMatches() + let manualSchedule = getManualMatches(); - if(manualSchedule === {}){ - - res.json({ - "allMatches": manualSchedule, - "currentMatch": ScoutingSync.match - }) + if(manualSchedule.length === 0){ + res.json({ + "allMatches": await ScoutingSync.getMatches(), + "currentMatch": ScoutingSync.match + }); } else { - res.json({ - "allMatches": await ScoutingSync.getMatches(), - "currentMatch": ScoutingSync.match - }) + res.json({ + "allMatches": manualSchedule, + "currentMatch": ScoutingSync.match + }); } }) module.exports = router; \ No newline at end of file diff --git a/src/schedule/schedule.js b/src/schedule/schedule.js index f5b0b7e6..e44dcc09 100644 --- a/src/schedule/schedule.js +++ b/src/schedule/schedule.js @@ -2,7 +2,7 @@ const { unwatchFile } = require("fs"); express = require("express"); -var schedule = {}; +var schedule = []; var tempTeams = []; let router = express.Router(); diff --git a/src/scouting/scouting-sync.js b/src/scouting/scouting-sync.js index 0cb7b995..e6075e39 100644 --- a/src/scouting/scouting-sync.js +++ b/src/scouting/scouting-sync.js @@ -69,11 +69,18 @@ class ScoutingSync { if (!config.secrets.TBA_API_KEY) { return []; //no key, no matches } + let tbaMatches = (await axios.get(`https://www.thebluealliance.com/api/v3/event/${config.TBA_EVENT_KEY}/matches`, { headers: { "X-TBA-Auth-Key": config.secrets.TBA_API_KEY } - }).catch(e => console.log(e,chalk.bold.red("\nError fetching matches from Blue Alliance Api!")))).data; + }).catch(e => console.log(e,chalk.bold.red("\nError fetching matches from Blue Alliance Api!")))); + + if (tbaMatches === undefined) { + return []; + } else { + tbaMatches = tbaMatches.data; + } //determine match numbers linearly (eg. if there are 10 quals, qf1 would be match 11) const matchLevels = ["qm", "ef", "qf", "sf", "f"]; @@ -126,7 +133,9 @@ class ScoutingSync { for (let scouter of ScoutingSync.scouters) { if (scouter.state.connected && scouter.state.status === ScoutingSync.SCOUTER_STATUS.WAITING) { //check to see if nextRobots is empty, if so repopulate it with all the robots in the match - if (nextRobots.size === 0) new Set(ScoutingSync.match.robots.red.concat(ScoutingSync.match.robots.blue)); + if (nextRobots.size >= 0) { + nextRobots = new Set(ScoutingSync.match.robots.red.concat(ScoutingSync.match.robots.blue)); + } //get the next robot number from the set (the set doesnt return robots in any particular order) let robotNumber = [...nextRobots][0]