From 2ea45b722a00d55be256c2983094e0b350e5eb88 Mon Sep 17 00:00:00 2001
From: Etienne LOUPIAS <eloupias@grandlyon.com>
Date: Fri, 7 Jun 2024 08:03:01 +0000
Subject: [PATCH] chore(structure): add ctm log

---
 src/structures/services/structures.service.ts | 8 +++++---
 src/structures/structures.controller.ts       | 4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts
index bf325484c..b398cd726 100644
--- a/src/structures/services/structures.service.ts
+++ b/src/structures/services/structures.service.ts
@@ -1334,9 +1334,11 @@ export class StructuresService {
     const structures: StructureDocument[] = await this.findAll();
     for (const structure of structures) {
       const updatedStructure = await this.setCtmTerritory(structure);
-      await this.structureModel
-        .findByIdAndUpdate(new Types.ObjectId(structure._id), updatedStructure, { timestamps: false })
-        .exec();
+      if (updatedStructure) {
+        await this.structureModel
+          .findByIdAndUpdate(new Types.ObjectId(structure._id), updatedStructure, { timestamps: false })
+          .exec();
+      }
     }
     return null;
   }
diff --git a/src/structures/structures.controller.ts b/src/structures/structures.controller.ts
index 01a595881..fe1b4c731 100644
--- a/src/structures/structures.controller.ts
+++ b/src/structures/structures.controller.ts
@@ -206,7 +206,9 @@ export class StructuresController {
   public async updateCTM(): Promise<void> {
     this.logger.log('updateCTM');
     await this.categoriesService.updateCTM();
-    return this.structureService.setCTMs();
+    await this.structureService.setCTMs();
+    this.logger.log('updateCTM done');
+    return
   }
 
   @Delete(':id')
-- 
GitLab