Skip to content

Commit

Permalink
filtering errors from airport detail
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgend committed Sep 8, 2021
1 parent 20670c9 commit 0f11953
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const buildAirportInfoCard = async (airport) => {
html = `<div class="airport-info-card">`;
html += `<h3>${airport.name}</h3>${airport.ident} - ${airport.iata_code} | ${airport.municipality},${airport.iso_country}`;

if (runways) {
if (runways && runways.length > 0) {
html += `<h4>Runways (${runways.length})</h4>`;
runways.forEach(r => { html += `‣ ${r.le_ident}/${r.he_ident} - ${r.surface.toLowerCase()}, ${parseFloat(r.length_ft).toFixed(1)}ft <br>`; });
}
Expand Down
22 changes: 17 additions & 5 deletions src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,18 @@ exports.searchAirports = async (start_lat, start_lng, end_lat, end_lng) => {
exports.getAirportDetail = async (icao) => {
const detail = {};

const metarResponse = await got(`https://sdm.virtualradarserver.co.uk/api/1.00/weather/airport/${icao}?_=${Date.now()}`, { responseType: 'json' });
if (metarResponse.statusCode === 200) {
detail.metar = metarResponse.body || {};
if (icao.includes('-')) {
return detail;
}

try {
const metarResponse = await got(`https://sdm.virtualradarserver.co.uk/api/1.00/weather/airport/${icao}?_=${Date.now()}`, { responseType: 'json' });
if (metarResponse.statusCode === 200) {
detail.metar = metarResponse.body || {};
}
}
catch (err) {
console.error(err);
}

const runwayCollection = await _mongoRepository.getCollection(_mongoRepository.schemaList.runway_icao);
Expand All @@ -48,9 +57,12 @@ exports.getAirportDetail = async (icao) => {

const raw = fs.readFileSync(path.join(__dirname, '../data', `runways.csv`), { encoding: 'utf8' });
const data = csvParse(raw, { columns: _dataHeaders.runways, skip_empty_lines: true, fromLine: 1 }).map(d => { d._id = d.id; return d; });
await runwayCollection.insertMany(data);

detail.runways = data.filter(r => r.airport_ident === icao);

if (detail.runways.length > 0) {
await runwayCollection.insertMany(data);
}

return detail;
};

Expand Down

0 comments on commit 0f11953

Please sign in to comment.