fix search
This commit is contained in:
parent
e9e72d8cea
commit
12949c1bba
2 changed files with 14 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"stationId": "9192",
|
"stationId": "9182",
|
||||||
"stationName": "Slussen",
|
"stationName": "Hökarängen",
|
||||||
"refreshRate": 10000
|
"refreshRate": 30000
|
||||||
}
|
}
|
||||||
|
|
@ -53,9 +53,16 @@ app.get('/api/sl/search', async (req, res) => {
|
||||||
if (!query) return res.status(400).json({ error: 'Query required' });
|
if (!query) return res.status(400).json({ error: 'Query required' });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`https://journeyplanner.integration.sl.se/v2/stop-finder?name_sf=${encodeURIComponent(query)}&format=json`);
|
const response = await fetch(`https://journeyplanner.integration.sl.se/v2/stop-finder?name_sf=${encodeURIComponent(query)}&format=json&type_sf=any&any_obj_filter_sf=2`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
res.json(data);
|
const locations: any[] = data.locations || [];
|
||||||
|
const StopLocation = locations
|
||||||
|
.filter((loc) => loc.type === 'stop' && loc.properties?.stopId)
|
||||||
|
.map((loc) => ({
|
||||||
|
id: loc.properties.stopId.replace(/^1800/, ''),
|
||||||
|
name: loc.disassembledName || loc.name,
|
||||||
|
}));
|
||||||
|
res.json({ StopLocation });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ error: 'Failed to search for station' });
|
res.status(500).json({ error: 'Failed to search for station' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue