Skip to content

Commit

Permalink
Merge pull request #13 from vatpac-technology/flights-api
Browse files Browse the repository at this point in the history
Added Flights API
  • Loading branch information
Kahn authored Apr 19, 2022
2 parents 3060f49 + 3c750f9 commit 216f8bf
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 3 deletions.
47 changes: 47 additions & 0 deletions APIS_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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
- 200 `[pilot]`
- 404
- 500

#### Callsign

Route `/callsign/<callsign>`
Returns
- 200 `{pilot}`
- 404
- 500

#### Departures

Route `/departures/<ICAO code>`
Returns
- 200 `[pilot]`
- 404
- 500
2 changes: 1 addition & 1 deletion config/default.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app": {
"name": "vatsim-map",
"version": "0.0.1",
"version": "0.0.3",
"url": "https://github.com/vatpac-technology/vatsim-map/",
"log_level": 30,
"http": {
Expand Down
2 changes: 1 addition & 1 deletion config/production.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app": {
"name": "vatsim-map",
"version": "0.0.2",
"version": "0.0.3",
"url": "https://github.com/vatpac-technology/vatsim-map/",
"log_level": 30,
"http": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vatsim-map",
"type": "module",
"version": "0.0.1",
"version": "0.0.3",
"description": "Display VATSIM traffic on a map for a given set of FIRs",
"private": true,
"dependencies": {
Expand Down
44 changes: 44 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,50 @@ app.get('/v1/pilots', cors(), async (req, res) => {
}
});

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 if(feature == undefined){
res.sendStatus(404);
}else{
res.send(feature.properties.pilot)
}
});

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(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)
}
});

app.get('/v1/atc/sectors', cors(), async (req, res) => {
var standardOnly = (req.query.standardOnly == undefined ? false : req.query.standardOnly.toString());
var sectors = await getATCSectors();
Expand Down

0 comments on commit 216f8bf

Please sign in to comment.