Skip to content

Commit

Permalink
Merge pull request #94 from Allybe/removeServerSideRequests
Browse files Browse the repository at this point in the history
Remove server side requests
  • Loading branch information
maaz-zubair-99 committed Jan 25, 2024
2 parents 25b66d8 + 7086150 commit a145a11
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
11 changes: 6 additions & 5 deletions src/admin/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let router = Router();
const config = require("../../../config/config.json");
const { TeamMatchPerformance } = require("../../lib/db");
let axios = require("axios")
const {getManualMatches} = require("../../schedule/schedule");
const DEMO = false;

router.use((req,res,next) => {
Expand Down Expand Up @@ -87,11 +88,11 @@ router.post("/setMatch", (req,res) => {
});

router.get("/matches", async (req,res) => {
//1 check if there is a manual schedu,e
//2 if there is a manual schedule, send it instead of the TBA one
//3 if there isnt send the TBA one
let manualSchedule = await axios.get(`http://localhost:${process.env.PORT || 8080}/schedule/matches`).then(res=>res.data) // temp fix
if(Object.keys(manualSchedule).length != 0){ // find a better way to check if its empty

let manualSchedule = getManualMatches()

if(manualSchedule === {}){

res.json({
"allMatches": manualSchedule,
"currentMatch": ScoutingSync.match
Expand Down
14 changes: 9 additions & 5 deletions src/analysis/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { Router } = require("express");
const executeAnalysisPipeline = require("../analysisPipeline.js")
const axios = require("axios")
const config = require("../../../config/config.json");
const {getTempTeams} = require("../../schedule/schedule");

let router = Router();

Expand All @@ -18,18 +19,21 @@ router.get("/teams", async (req, res) => {
return res.json([]); //no key, no teams
}

var teams = [];
let teams = [];

teams = getTempTeams();

if (teams.length === 0) {

teams = await axios.get(`http://localhost:${process.env.PORT || 8080}/schedule/tempteams`).then(res=> res.data);
if (teams.length == 0) {
teams = (await axios.get(`https://www.thebluealliance.com/api/v3/event/${config.TBA_EVENT_KEY}/teams`, {
headers: {
"X-TBA-Auth-Key": config.secrets.TBA_API_KEY
}
}).catch(e => console.log(e,chalk.bold.red("\nError fetching teams from Blue Alliance API!")))).data;

}).catch(e => console.error(e, chalk.bold.red("\nError fetching teams from Blue Alliance API!")))).data;
}

console.log(teams);

res.json(teams);
})

Expand Down
19 changes: 12 additions & 7 deletions src/schedule/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ router.post('/matches',(req,res)=>{

res.send(200)
})
router.get('/matches',(req,res)=>{
res.send(schedule);
})


router.use("/api", require("./routes/api.js"));

router.get("/tempteams", async (req, res) => {
res.send(tempTeams);
});
function getManualMatches() {
return schedule;
}

function getTempTeams() {
return tempTeams;
}


const addTeam = (matchLists) => {
var teams = [];
Expand All @@ -52,4 +55,6 @@ const addTeam = (matchLists) => {
tempTeams = teams;
}

module.exports = router;

module.exports = {router, getTempTeams, getManualMatches};

0 comments on commit a145a11

Please sign in to comment.