fix search

This commit is contained in:
cediackermann 2026-04-20 18:16:23 +02:00
parent e9e72d8cea
commit 12949c1bba
2 changed files with 14 additions and 7 deletions

View file

@ -1,5 +1,5 @@
{ {
"stationId": "9192", "stationId": "9182",
"stationName": "Slussen", "stationName": "Hökarängen",
"refreshRate": 10000 "refreshRate": 30000
} }

View file

@ -51,11 +51,18 @@ app.get('/api/sl/departures/:siteId', async (req, res) => {
app.get('/api/sl/search', async (req, res) => { app.get('/api/sl/search', async (req, res) => {
const query = req.query.q as string; const query = req.query.q as string;
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' });
} }