Fix car link: use airport coords and IATA instead of factory location

This commit is contained in:
Timo
2026-03-17 09:29:51 +01:00
parent fad146519b
commit 798418b317

View File

@@ -305,16 +305,17 @@ function generateHotelLink({ cityName, checkin, checkout, adults, refundableOnly
return url; return url;
} }
function generateCarLink({ cityName, iataCode, pickupDate, dropoffDate, lat, lng }) { function generateCarLink({ cityName, iataCode, pickupDate, dropoffDate, lat, lng, airportName }) {
const pu = new Date(pickupDate); const pu = new Date(pickupDate);
const doDate = new Date(dropoffDate); const doDate = new Date(dropoffDate);
const displayName = airportName || (iataCode ? `Flughafen ${iataCode}` : cityName);
const params = new URLSearchParams({ const params = new URLSearchParams({
preflang: 'de', preflang: 'de',
prefcurrency: 'EUR', prefcurrency: 'EUR',
driversAge: '30', driversAge: '30',
locationName: iataCode ? `Flughafen ${cityName}` : cityName, locationName: displayName,
locationIata: iataCode || '', locationIata: iataCode || '',
dropLocationName: iataCode ? `Flughafen ${cityName}` : cityName, dropLocationName: displayName,
dropLocationIata: iataCode || '', dropLocationIata: iataCode || '',
puDay: pu.getUTCDate(), puDay: pu.getUTCDate(),
puMonth: pu.getUTCMonth() + 1, puMonth: pu.getUTCMonth() + 1,
@@ -438,10 +439,24 @@ app.post('/api/search', async (req, res) => {
const hotelLink = generateHotelLink({ const hotelLink = generateHotelLink({
cityName: destinationCity, checkin, checkout, adults, refundableOnly, cityName: destinationCity, checkin, checkout, adults, refundableOnly,
}); });
// Flughafen-Koordinaten für Mietwagen (Abholung am Flughafen, nicht an der Fabrik)
let airportCoords = null;
let airportName = null;
if (destIATA) {
try {
const r = await geocodeAddress(`${destIATA} airport`);
airportCoords = r;
airportName = `Flughafen ${destIATA}`;
} catch (_) {}
}
const carLink = generateCarLink({ const carLink = generateCarLink({
cityName: destinationCity, iataCode: destIATA, cityName: destinationCity, iataCode: destIATA,
pickupDate: checkin, dropoffDate: checkout, pickupDate: checkin, dropoffDate: checkout,
lat: destCoords?.lat, lng: destCoords?.lng, lat: airportCoords?.lat ?? destCoords?.lat,
lng: airportCoords?.lng ?? destCoords?.lng,
airportName,
}); });
res.json({ res.json({