From 608b09c07ec944aee5238359fc28a99fd44cee09 Mon Sep 17 00:00:00 2001 From: Paul Makles <paulmakles@gmail.com> Date: Sun, 25 Nov 2018 21:25:06 +0000 Subject: [PATCH] Can add actual stops now --- App.js | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/App.js b/App.js index d782b91..2e26d27 100644 --- a/App.js +++ b/App.js @@ -104,18 +104,45 @@ const request = { }, search: query => { return new Promise((resolve, reject) => { + // avoid stopType = NaptanRailEntrance + // if [NaptanOnstreetBusCoachStopCluster, NaptanOnstreetBusCoachStopPair] get child and process + // add NaptanPublicBusCoachTram [check indicator] = "e.g. Stop Y" fetch('https://api.tfl.gov.uk/StopPoint/Search/' + query) .then(response => response.json()) .then(source => { - let data = []; + let search = []; source.matches.forEach(res => { - data.push({ - id: res.id, - modes: res.modes, - name: res.name, - }); + search.push(res.id); }); - resolve(data); + fetch('https://api.tfl.gov.uk/StopPoint/' + search.join(',')) + .then(response => response.json()) + .then(source => { + let data = []; + let process = (x, name) => { + if (['NaptanOnstreetBusCoachStopCluster', 'NaptanOnstreetBusCoachStopPair'].indexOf(x.stopType) > -1) { + x.children.forEach(y => process(y)); + } else if (x.stopType == 'NaptanPublicBusCoachTram') { + let name = x.commonName; + if (x.indicator) { + name += ` [${x.indicator}]` + } + data.push({ + id: x.id, + name, + //modes: res.modes, + }); + } + }; + if (search.length > 1) { + source.forEach(res => { + process(res); + }); + } else { + process(source); + } + resolve(data); + }) + .catch(reject); }) .catch(reject); }); -- GitLab