From 48383420588f4b221dbf920f65e30e8da9def88f Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Tue, 26 Jan 2021 15:06:59 +0100
Subject: [PATCH] fix: fix duplication bug from aptic structure

---
 src/structures/services/aptic-structures.service.ts | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/structures/services/aptic-structures.service.ts b/src/structures/services/aptic-structures.service.ts
index 38941c0d7..9ba852e91 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');
-- 
GitLab