diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index bf325484cbd7f1dda06e79530e7ddfbf81fa0c05..b398cd726917eed2689299d3c8cb2b0c1f6bf794 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 01a59588116d756204f22dadf6f79d2af7f32a70..fe1b4c7314f4a586daf521bb2c47309d7bc42dd7 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')