From 3b675eed607c64e671574152d843b959241560a8 Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 30 Oct 2026 17:14:55 +0100 Subject: [PATCH] airports: publish the airport of a code as a contract the place search reads The search turned an airport code into its airport by reaching into the airports domain's data module. airports.contract.ts publishes that lookup instead, as the import boundaries ask. --- server/src/nest/airports/airports.contract.ts | 20 +++++++++++++++++++ .../src/nest/maps/providers/osm-geocoding.ts | 8 ++++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 server/src/nest/airports/airports.contract.ts diff --git a/server/src/nest/airports/airports.contract.ts b/server/src/nest/airports/airports.contract.ts new file mode 100644 index 000000000..f35d727f5 --- /dev/null +++ b/server/src/nest/airports/airports.contract.ts @@ -0,0 +1,20 @@ +/** + * What the airports domain offers other domains without its service: the + * bundled airport of an IATA code. The place search reads it to turn "JFK" + * into the airport it names (maps/providers/osm-geocoding.ts), a lookup in + * memory that needs neither the database nor the module. + */ +import { findByIata } from './airports.data'; + +/** An airport by name and coordinate, the part of it a lookup by code hands on. */ +export interface AirportByCode { + iata: string; + name: string; + lat: number; + lng: number; +} + +export function airportByCode(code: string): AirportByCode | null { + const airport = findByIata(code); + return airport ? { iata: airport.iata, name: airport.name, lat: airport.lat, lng: airport.lng } : null; +} diff --git a/server/src/nest/maps/providers/osm-geocoding.ts b/server/src/nest/maps/providers/osm-geocoding.ts index 487baeb61..2adb12015 100644 --- a/server/src/nest/maps/providers/osm-geocoding.ts +++ b/server/src/nest/maps/providers/osm-geocoding.ts @@ -9,7 +9,7 @@ * the installation's geocoder these answer alone; Nominatim is OsmClient's * business, for installations without the TREK services. */ -import { findByIata, type Airport } from '../../airports/airports.data'; +import { airportByCode, type AirportByCode } from '../../airports/airports.contract'; import { buildOsmDetails, haversineMetres, namesOverlap, toApiLang } from '../maps.helpers'; import type { NominatimResult, NominatimReverse, OverpassElement } from './osm.client'; import type { PhotonClient } from './photon.client'; @@ -100,9 +100,9 @@ export async function photonSuggest( * coordinate, where the aerodrome comes first. Lower case is left alone, so * "Ber" typed on the way to "Berlin" stays a search for Berlin. */ -function airportOfCode(query: string): Airport | null { +function airportOfCode(query: string): AirportByCode | null { const code = query.trim(); - return /^[A-Z]{3}$/.test(code) ? findByIata(code) : null; + return /^[A-Z]{3}$/.test(code) ? airportByCode(code) : null; } /** @@ -111,7 +111,7 @@ function airportOfCode(query: string): Airport | null { * airport, which is how OpenStreetMap files Haneda (an island named "Tokyo * International Airport"). */ -function airportLead(ranked: PhotonFeature[], airport: Airport): PhotonLead | null { +function airportLead(ranked: PhotonFeature[], airport: AirportByCode): PhotonLead | null { const near = ranked .map((feature) => ({ feature, row: asSuggestion(feature) })) .filter(