From 7e3f686121fca7a32a67c3267771d3b855b8a016 Mon Sep 17 00:00:00 2001
From: Etienne LOUPIAS <eloupias@grandlyon.com>
Date: Fri, 10 Mar 2023 15:54:21 +0000
Subject: [PATCH] fix(structure): avoid date update in CTM script

---
 scripts/data/structures.js                    | 18 +++++++++---------
 src/structures/services/structures.service.ts |  6 ++++--
 src/structures/structures.controller.ts       |  4 ++--
 src/tcl/tclStopPoint.controller.ts            |  6 +++---
 4 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/scripts/data/structures.js b/scripts/data/structures.js
index 9de10021f..6298725cb 100644
--- a/scripts/data/structures.js
+++ b/scripts/data/structures.js
@@ -5,7 +5,7 @@ module.exports = {
   data: [
     {
       _id: mongoose.Types.ObjectId('6001a35f16b08100062e415f'),
-      freeWorkShop: false,
+      freeWorkShop: 'Non',
       createdAt: '2020-11-16T15:37:00.000Z',
       updatedAt: '2021-03-02T12:36:53.000Z',
       structureName: "Maison de l'Emploi (Feyzin)",
@@ -164,7 +164,7 @@ module.exports = {
         handicaps: ['physicalDisability'],
         publicOthers: ['uniquementFemmes'],
       },
-      freeWorkShop: false,
+      freeWorkShop: 'Non',
       createdAt: '2020-11-16T10:19:00.000Z',
       updatedAt: '2020-12-16T10:19:00.000Z',
       structureName: 'Pôle emploi (Vénissieux)',
@@ -270,7 +270,7 @@ module.exports = {
     },
     {
       _id: mongoose.Types.ObjectId('6001a38516b08100062e4161'),
-      freeWorkShop: false,
+      freeWorkShop: 'Non',
       createdAt: '2020-11-16T14:15:00.000Z',
       updatedAt: '2021-04-27T14:19:17.000Z',
       structureName: 'Centre social Quartier Vitalité',
@@ -371,7 +371,7 @@ module.exports = {
         handicaps: ['physicalDisability'],
         publicOthers: ['uniquementFemmes'],
       },
-      freeWorkShop: false,
+      freeWorkShop: 'Non',
       createdAt: '2020-11-16T09:30:00.000Z',
       updatedAt: '2021-04-12T08:48:00.000Z',
       structureName: "L'Atelier Numérique",
@@ -514,7 +514,7 @@ module.exports = {
         handicaps: ['physicalDisability'],
         publicOthers: ['uniquementFemmes'],
       },
-      freeWorkShop: false,
+      freeWorkShop: 'Non',
       createdAt: '2020-11-16T08:53:00.000Z',
       updatedAt: '2021-04-27T17:06:46.000Z',
       structureName: 'Cyber-base / MJC Louis Aragon',
@@ -618,7 +618,7 @@ module.exports = {
         handicaps: ['physicalDisability'],
         publicOthers: ['uniquementFemmes'],
       },
-      freeWorkShop: false,
+      freeWorkShop: 'Non',
       createdAt: '2020-11-04T09:27:00.000Z',
       updatedAt: '2021-03-02T10:07:48.000Z',
       structureName: 'Oasis Informatique',
@@ -730,7 +730,7 @@ module.exports = {
         handicaps: ['physicalDisability'],
         publicOthers: ['uniquementFemmes'],
       },
-      freeWorkShop: false,
+      freeWorkShop: 'Non',
       createdAt: '2020-11-13T14:13:00.000Z',
       updatedAt: '2021-03-02T10:09:30.000Z',
       structureName: 'Le Son du Clic',
@@ -848,7 +848,7 @@ module.exports = {
       pmrAccess: false,
       remoteAccompaniment: false,
       accountVerified: true,
-      freeWorkShop: false,
+      freeWorkShop: 'Non',
       nbComputers: 0,
       nbPrinters: 0,
       nbScanners: 0,
@@ -917,7 +917,7 @@ module.exports = {
       pmrAccess: false,
       remoteAccompaniment: false,
       accountVerified: true,
-      freeWorkShop: false,
+      freeWorkShop: 'Non',
       nbComputers: 0,
       nbPrinters: 0,
       nbScanners: 0,
diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts
index 0c7293519..2b8e21dd8 100644
--- a/src/structures/services/structures.service.ts
+++ b/src/structures/services/structures.service.ts
@@ -7,7 +7,7 @@ import * as ejs from 'ejs';
 import * as _ from 'lodash';
 import { DateTime } from 'luxon';
 import { DocumentDefinition, FilterQuery, Model, Types } from 'mongoose';
-import { lastValueFrom, map, Observable, tap } from 'rxjs';
+import { lastValueFrom, map, tap } from 'rxjs';
 import { PendingStructureDto } from '../../admin/dto/pending-structure.dto';
 import { UnclaimedStructureDto } from '../../admin/dto/unclaimed-structure-dto';
 import { Categories } from '../../categories/schemas/categories.schema';
@@ -1162,7 +1162,9 @@ export class StructuresService {
     const structures: StructureDocument[] = await this.findAll();
     for (const structure of structures) {
       this.setCtmTerritory(structure).then(async (updatedStructure) => {
-        await this.structureModel.findByIdAndUpdate(new Types.ObjectId(structure._id), updatedStructure).exec();
+        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 b354a6821..c076dc323 100644
--- a/src/structures/structures.controller.ts
+++ b/src/structures/structures.controller.ts
@@ -181,10 +181,10 @@ export class StructuresController {
     description: `Mettre à jour les territoires CTM des structures à partir de Data Grand Lyon`,
   })
   @ApiResponse({
-    status: 204,
+    status: 201,
     description: 'The CTM territories have been updated successfully.',
   })
-  @Get('/ctm/update')
+  @Post('/ctm/update')
   @UseGuards(JwtAuthGuard, RolesGuard)
   @Roles('admin')
   public async updateCTM(): Promise<void> {
diff --git a/src/tcl/tclStopPoint.controller.ts b/src/tcl/tclStopPoint.controller.ts
index b649e3df4..e49137f1e 100644
--- a/src/tcl/tclStopPoint.controller.ts
+++ b/src/tcl/tclStopPoint.controller.ts
@@ -1,4 +1,4 @@
-import { Body, Controller, Get, Logger, Post, UseGuards } from '@nestjs/common';
+import { Body, Controller, Logger, Post, UseGuards } from '@nestjs/common';
 import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
 import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
 import { Roles } from '../users/decorators/roles.decorator';
@@ -17,10 +17,10 @@ export class TclStopPointController {
     description: `Mettre à jour les points d'arrêt TCL à partir de Data Grand Lyon`,
   })
   @ApiResponse({
-    status: 204,
+    status: 201,
     description: 'The stop points have been updated successfully.',
   })
-  @Get('/update')
+  @Post('/update')
   @UseGuards(JwtAuthGuard, RolesGuard)
   @Roles('admin')
   public updateStopPoints(): Promise<void> {
-- 
GitLab