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

Remove server side requests #94

Merged
merged 5 commits into from
Jan 25, 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
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};