From ff91305ee2a2f687bbc0de2395214df942b6fe68 Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Mon, 3 Apr 2023 10:22:25 +0200 Subject: [PATCH] chore(photon): add type safety --- .../interfaces/photon-response.interface.ts | 19 +++++++++++++++++++ src/structures/structures.controller.ts | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/structures/interfaces/photon-response.interface.ts diff --git a/src/structures/interfaces/photon-response.interface.ts b/src/structures/interfaces/photon-response.interface.ts new file mode 100644 index 000000000..840ce7d36 --- /dev/null +++ b/src/structures/interfaces/photon-response.interface.ts @@ -0,0 +1,19 @@ +export interface PhotonPoints { + geometry: { + coordinates: number[]; + type: string; + }; + type: string; + properties: { + osm_id: number; + osm_type: string; + extent?: number[]; + country: string; + osm_key: string; + osm_value: string; + name?: string; + state: string; + city?: string; + postcode?: string; + }; +} diff --git a/src/structures/structures.controller.ts b/src/structures/structures.controller.ts index d26535088..de8759a43 100644 --- a/src/structures/structures.controller.ts +++ b/src/structures/structures.controller.ts @@ -37,6 +37,7 @@ import { depRegex } from './common/regex'; import { CreateStructureDto } from './dto/create-structure.dto'; import { QueryStructure } from './dto/query-structure.dto'; import { UpdateStructureDto } from './dto/update-structure.dto'; +import { PhotonPoints } from './interfaces/photon-response.interface'; import { Structure, StructureDocument } from './schemas/structure.schema'; import { StructuresService } from './services/structures.service'; @@ -67,7 +68,7 @@ export class StructuresController { .then(async (res) => res.data.features) .then((data) => data.filter( - (cityPoint) => + (cityPoint: PhotonPoints) => /* check if query sting = postcode OR query string = city (without hyphens and diacritics) OR query string = name (in 2 cases, Charly et Rochetaillée-sur-saône, the city name is in the name field and the city field is missing) */ -- GitLab