diff --git a/src/structures/structures.controller.ts b/src/structures/structures.controller.ts index 9385e2d525474907eeb7e5ee8d074da1deeff24a..19f13b6fb8deac03871d8bed25557588f544a56c 100644 --- a/src/structures/structures.controller.ts +++ b/src/structures/structures.controller.ts @@ -37,6 +37,7 @@ import { QueryStructure } from './dto/query-structure.dto'; import { UpdateStructureDto } from './dto/update-structure.dto'; import { Structure, StructureDocument } from './schemas/structure.schema'; import { StructuresService } from './services/structures.service'; +import * as _ from 'lodash'; @ApiTags('structures') @Controller('structures') @@ -66,8 +67,15 @@ export class StructuresController { .then((data) => data.filter( (cityPoint) => + /* 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) */ (cityPoint.properties.postcode == city || - cityPoint.properties.city?.toLowerCase().includes(city.toLowerCase())) && + _.deburr(cityPoint.properties.city?.toLowerCase().replace(/\-/g, ' ')).includes( + _.deburr(city).toLowerCase().replace(/\-/g, ' ') + ) || + _.deburr(cityPoint.properties.name?.toLowerCase().replace(/\-/g, ' ')) === + _.deburr(city).toLowerCase().replace(/\-/g, ' ')) && cityPoint.properties.postcode.match(depRegex) ) )