Skip to content

Commit

Permalink
Created initial flights API #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Kahn committed Apr 16, 2022
1 parent d9483d3 commit c54afa2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
38 changes: 38 additions & 0 deletions APIS_README.md
Original file line number Diff line number Diff line change
@@ -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/<ICAO code>`
Returns `[pilot]`

#### Callsign

Route `/callsign/<callsign>`
Returns `{pilot}`

#### Departures

Route `/departures/<ICAO code>`
Returns `[pilot]`
45 changes: 36 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
});

Expand Down

0 comments on commit c54afa2

Please sign in to comment.