From c54afa27443788b696d0562e34cae279e7ed746b Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Sat, 16 Apr 2022 23:11:44 +1000 Subject: [PATCH] Created initial flights API #6 --- APIS_README.md | 38 ++++++++++++++++++++++++++++++++++++++ server.js | 45 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 APIS_README.md diff --git a/APIS_README.md b/APIS_README.md new file mode 100644 index 0000000..13af226 --- /dev/null +++ b/APIS_README.md @@ -0,0 +1,38 @@ +# Maps REST API + +The map API extends the VATSIM data API in a short lived cache. There is no persistent data. + +## Types + +### Pilot + +As per https://data.vatsim.net/v3/vatsim-data.json with the following extensions. + +```javascript + "aerodrome": false, + "tag_alt": "A043", + "tag_gs": "0" +``` + +## Routes + +Route `/v1/` + +### Flights + +Route `/flights/` + +#### Arivals + +Route `/arrivals/` +Returns `[pilot]` + +#### Callsign + +Route `/callsign/` +Returns `{pilot}` + +#### Departures + +Route `/departures/` +Returns `[pilot]` diff --git a/server.js b/server.js index e918ab3..ccc9105 100644 --- a/server.js +++ b/server.js @@ -51,18 +51,45 @@ app.get('/v1/pilots', cors(), async (req, res) => { } }); -app.get('/v1/atc/sectors', cors(), async (req, res) => { - var standardOnly = (req.query.standardOnly == undefined ? false : req.query.standardOnly.toString()); - var sectors = await getATCSectors(); - if (standardOnly == "true"){ - sectors = sectors.filter(function(sector) { - return sector.standard_position===true; - }); +app.get('/v1/flights/callsign/:callsign', cors(), async (req, res) => { + const pilots = await getPilots(); + const feature = pilots.features.find(e => e.properties.pilot.callsign === req.params.callsign) + if(feature == false){ + res.sendStatus(500); + }else{ + res.send(feature.properties.pilot) } - if(sectors == false){ +}); + +app.get('/v1/flights/arrivals/:icaoCode', cors(), async (req, res) => { + const pilotData = await getPilots(); + var features = false; + var pilots = []; + try{ + features = pilotData.features.filter(e => e.properties.pilot.flight_plan.arrival === req.params.icaoCode) + features.forEach(function(e){pilots.push(e.properties.pilot)}) + } catch (e) {} + + if(features == false){ res.sendStatus(500); }else{ - res.send(sectors) + res.send(pilots) + } +}); + +app.get('/v1/flights/departures/:icaoCode', cors(), async (req, res) => { + const pilotData = await getPilots(); + var features = false; + var pilots = []; + try{ + features = pilotData.features.filter(e => e.properties.pilot.flight_plan.departure === req.params.icaoCode) + features.forEach(function(e){pilots.push(e.properties.pilot)}) + } catch (e) {} + + if(features == false){ + res.sendStatus(500); + }else{ + res.send(pilots) } });