diff --git a/src/structures/services/aptic-structures.service.ts b/src/structures/services/aptic-structures.service.ts index 38941c0d725cfdc094378a791ce483cf2e86e8c5..9ba852e91fec49df78d294f94d97fce000ce2cdf 100644 --- a/src/structures/services/aptic-structures.service.ts +++ b/src/structures/services/aptic-structures.service.ts @@ -45,6 +45,7 @@ export class ApticStructuresService { private async createApticStructures(structure: ApticStructure): Promise<any> { this.structureAlreadyExist(structure).then((exist) => { if (!exist) { + Logger.log(`Create structure : ${structure.presence_name}`, 'ApticStructuresService - createApticStructures'); const createdStructure = new this.structureModel(); createdStructure.coord = [structure.gps_lng, structure.gps_lat]; createdStructure.structureName = structure.presence_name; @@ -61,16 +62,17 @@ export class ApticStructuresService { } private async structureAlreadyExist(structure: ApticStructure): Promise<boolean> { - const existingStructure = await this.structureModel + let existingStructure = await this.structureModel .findOne({ structureName: { $regex: structure.presence_name, $options: 'i' }, }) .exec(); + // Check without regex for case like 'TINEBRA*DANIEL/DANIEL/' + if (!existingStructure) { + existingStructure = await this.structureModel.findOne({ structureName: structure.presence_name }).exec(); + } + if (existingStructure) { - Logger.log( - `Cannot create structure, it already exist : ${existingStructure.structureName}`, - 'ApticStructuresService - structureAlreadyExist' - ); // Add aptic label if it's not the case if (!existingStructure.labelsQualifications.includes('passNumerique')) { existingStructure.labelsQualifications.push('passNumerique');