From 572c2a6c7d213d97731552557b943a7297bb77c5 Mon Sep 17 00:00:00 2001 From: hbalty Date: Tue, 12 Aug 2025 00:35:09 +0200 Subject: [PATCH 1/4] feat(structures): making sms day mandatory --- .../structures-sms-form.component.html | 2 +- .../structures-sms-form.component.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.html b/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.html index a6b1ec7877..5de161438a 100644 --- a/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.html +++ b/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.html @@ -203,7 +203,7 @@

Paramètres d'envoi de SMS pour votre structure

- + Quel(s) jour(s) souhaitez-vous envoyer les SMS (2 jours par semaine maximum) diff --git a/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts b/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts index 6136cf7631..66ee686b8d 100644 --- a/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts +++ b/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts @@ -125,6 +125,11 @@ export class StructuresSmsFormComponent implements OnInit, OnDestroy { return; } + if (this.structureSmsForm.errors?.atLeastOneDay) { + this.toastService.error("Veuillez sélectionner au moins un jour"); + return; + } + if (this.structureSmsForm.invalid) { this.toastService.error("Veuillez vérifier le formulaire"); return; @@ -173,6 +178,14 @@ export class StructuresSmsFormComponent implements OnInit, OnDestroy { count++; } }); - return count <= 2 ? null : { moreThanTwoDays: true }; + if (count >= 2) { + return { moreThanTwoDays: true }; + } + + if (count === 0) { + return { atLeastOneDay: true }; + } + + return null; }; } From a7c3bb140ce1eaa6fa582cc7654ee60455c158b7 Mon Sep 17 00:00:00 2001 From: Houssem Balty Date: Tue, 12 Aug 2025 00:42:29 +0200 Subject: [PATCH 2/4] Update packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts Co-authored-by: Revu --- .../structures-sms-form/structures-sms-form.component.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts b/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts index 66ee686b8d..e3665d179d 100644 --- a/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts +++ b/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts @@ -178,13 +178,13 @@ export class StructuresSmsFormComponent implements OnInit, OnDestroy { count++; } }); - if (count >= 2) { - return { moreThanTwoDays: true }; - } - if (count === 0) { return { atLeastOneDay: true }; } + + if (count > 2) { + return { moreThanTwoDays: true }; + } return null; }; From 6ba95bb984ce28126c9b2b3f658de4cb0f6e7116 Mon Sep 17 00:00:00 2001 From: hbalty Date: Tue, 12 Aug 2025 23:56:41 +0200 Subject: [PATCH 3/4] feat(structures): adding migration to set default value to structure sms schedule --- .../1755033531923-manual-migration.ts | 66 +++++++++++++++++++ .../structure/StructureTable.typeorm.ts | 2 +- .../controllers/structures.controller.ts | 7 ++ .../modules/structures/dto/schedule.dto.ts | 1 - .../structures-sms-form.component.ts | 1 - 5 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 packages/backend/src/_migrations/1755033531923-manual-migration.ts diff --git a/packages/backend/src/_migrations/1755033531923-manual-migration.ts b/packages/backend/src/_migrations/1755033531923-manual-migration.ts new file mode 100644 index 0000000000..2d618f612d --- /dev/null +++ b/packages/backend/src/_migrations/1755033531923-manual-migration.ts @@ -0,0 +1,66 @@ +import { MigrationInterface } from "typeorm"; +import { domifaConfig } from "../config"; +import { structureRepository } from "../database"; +import { StructureSmsParams } from "@domifa/common"; +import { appLogger } from "../util"; + +export class ManualMigration1755033531923 implements MigrationInterface { + name: string = "ManualMigration1755033531923"; + public async up(): Promise { + const emailList = []; + if ( + domifaConfig().envId === "prod" || + domifaConfig().envId === "preprod" || + domifaConfig().envId === "local" + ) { + appLogger.info("Starting migration: Updating structures SMS schedules"); + + const structures = await structureRepository.find({ + select: { + id: true, + email: true, + sms: true, + }, + }); + + const structuresWithoutSmsSchedule = structures.filter( + (s) => !Object.values(s.sms?.schedule).some((value) => value === true) + ); + + // Process each structure record + for (const structure of structuresWithoutSmsSchedule) { + const smsParams: StructureSmsParams = { + ...structure.sms, + schedule: { + ...structure.sms.schedule, + tuesday: true, + thursday: true, + }, + }; + + await structureRepository.update( + { + id: structure.id, + }, + { + sms: smsParams, + } + ); + + emailList.push(structure.email); + } + appLogger.info("Migration end"); + appLogger.info("Liste des emails des structures à contacter:", emailList); + } + } + + public async down(): Promise { + if ( + domifaConfig().envId === "prod" || + domifaConfig().envId === "preprod" || + domifaConfig().envId === "local" + ) { + appLogger.info("No down migration can be applied"); + } + } +} diff --git a/packages/backend/src/database/entities/structure/StructureTable.typeorm.ts b/packages/backend/src/database/entities/structure/StructureTable.typeorm.ts index f77e9af191..71c46667c2 100644 --- a/packages/backend/src/database/entities/structure/StructureTable.typeorm.ts +++ b/packages/backend/src/database/entities/structure/StructureTable.typeorm.ts @@ -131,7 +131,7 @@ export class StructureTable @Column({ type: "jsonb", default: () => - `'{"senderName": null, "senderDetails": null, "enabledByDomifa": true, "enabledByStructure": false, "schedule" :{ "monday": false "tuesday": false "wednesday": false "thursday": false "friday": false } }'`, + `'{"senderName": null, "senderDetails": null, "enabledByDomifa": true, "enabledByStructure": false, "schedule" :{ "monday": false "tuesday": true "wednesday": false "thursday": true "friday": false } }'`, }) public sms: StructureSmsParams; diff --git a/packages/backend/src/modules/structures/controllers/structures.controller.ts b/packages/backend/src/modules/structures/controllers/structures.controller.ts index 703e476b36..fa7c930e13 100644 --- a/packages/backend/src/modules/structures/controllers/structures.controller.ts +++ b/packages/backend/src/modules/structures/controllers/structures.controller.ts @@ -98,6 +98,13 @@ export class StructuresController { const values = Object.values(structureSmsDto.schedule); const checkedDaysCount = values.filter((value) => value === true).length; + + if (checkedDaysCount === 0) { + return res + .status(HttpStatus.BAD_REQUEST) + .json({ message: "MUST_SET_AT_LEAST_1_DAY" }); + } + if (checkedDaysCount > 2) { return res .status(HttpStatus.BAD_REQUEST) diff --git a/packages/backend/src/modules/structures/dto/schedule.dto.ts b/packages/backend/src/modules/structures/dto/schedule.dto.ts index b0357b3bba..16bcc88be8 100644 --- a/packages/backend/src/modules/structures/dto/schedule.dto.ts +++ b/packages/backend/src/modules/structures/dto/schedule.dto.ts @@ -1,5 +1,4 @@ import { IsBoolean } from "class-validator"; - export class ScheduleDto { @IsBoolean() monday: boolean; diff --git a/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts b/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts index e3665d179d..dc143c7fcb 100644 --- a/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts +++ b/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.ts @@ -181,7 +181,6 @@ export class StructuresSmsFormComponent implements OnInit, OnDestroy { if (count === 0) { return { atLeastOneDay: true }; } - if (count > 2) { return { moreThanTwoDays: true }; } From 6679f0430c75addfc9fcb9ef225c1e8cecea4fef Mon Sep 17 00:00:00 2001 From: hbalty Date: Thu, 14 Aug 2025 11:43:06 +0200 Subject: [PATCH 4/4] fix(backend): fixing reviews --- .../1755033531923-manual-migration.ts | 63 +++++++------------ .../services/structureCreator.service.ts | 4 +- .../structures-sms-form.component.html | 10 +++ 3 files changed, 36 insertions(+), 41 deletions(-) diff --git a/packages/backend/src/_migrations/1755033531923-manual-migration.ts b/packages/backend/src/_migrations/1755033531923-manual-migration.ts index 2d618f612d..1f84bcb366 100644 --- a/packages/backend/src/_migrations/1755033531923-manual-migration.ts +++ b/packages/backend/src/_migrations/1755033531923-manual-migration.ts @@ -1,56 +1,41 @@ -import { MigrationInterface } from "typeorm"; +import { MigrationInterface, QueryRunner } from "typeorm"; import { domifaConfig } from "../config"; -import { structureRepository } from "../database"; -import { StructureSmsParams } from "@domifa/common"; import { appLogger } from "../util"; export class ManualMigration1755033531923 implements MigrationInterface { name: string = "ManualMigration1755033531923"; - public async up(): Promise { - const emailList = []; + public async up(queryRunner: QueryRunner): Promise { if ( domifaConfig().envId === "prod" || domifaConfig().envId === "preprod" || domifaConfig().envId === "local" ) { appLogger.info("Starting migration: Updating structures SMS schedules"); + await queryRunner.query(` + UPDATE structure + SET sms = sms || '{"schedule": {"monday": false, "tuesday": true, "wednesday": false, "thursday": true, "friday": false}}'::jsonb + WHERE + (sms->>'enabledByStructure')::boolean = TRUE + AND (sms->'schedule'->>'friday')::boolean = FALSE + AND (sms->'schedule'->>'monday')::boolean = FALSE + AND (sms->'schedule'->>'thursday')::boolean = FALSE + AND (sms->'schedule'->>'tuesday')::boolean = FALSE + AND (sms->'schedule'->>'wednesday')::boolean = FALSE; + `); - const structures = await structureRepository.find({ - select: { - id: true, - email: true, - sms: true, - }, - }); + const count = await queryRunner.query(` + SELECT COUNT(*) FROM structure + WHERE + (sms->>'enabledByStructure')::boolean = TRUE + AND (sms->'schedule'->>'friday')::boolean = FALSE + AND (sms->'schedule'->>'monday')::boolean = FALSE + AND (sms->'schedule'->>'thursday')::boolean = FALSE + AND (sms->'schedule'->>'tuesday')::boolean = FALSE + AND (sms->'schedule'->>'wednesday')::boolean = FALSE; + `); - const structuresWithoutSmsSchedule = structures.filter( - (s) => !Object.values(s.sms?.schedule).some((value) => value === true) - ); - - // Process each structure record - for (const structure of structuresWithoutSmsSchedule) { - const smsParams: StructureSmsParams = { - ...structure.sms, - schedule: { - ...structure.sms.schedule, - tuesday: true, - thursday: true, - }, - }; - - await structureRepository.update( - { - id: structure.id, - }, - { - sms: smsParams, - } - ); - - emailList.push(structure.email); - } + console.log(count); appLogger.info("Migration end"); - appLogger.info("Liste des emails des structures à contacter:", emailList); } } diff --git a/packages/backend/src/modules/structures/services/structureCreator.service.ts b/packages/backend/src/modules/structures/services/structureCreator.service.ts index bb265d9d1a..4d101e6490 100644 --- a/packages/backend/src/modules/structures/services/structureCreator.service.ts +++ b/packages/backend/src/modules/structures/services/structureCreator.service.ts @@ -112,9 +112,9 @@ async function createStructure(structureDto: StructureDto) { enabledByStructure: false, schedule: { monday: false, - tuesday: false, + tuesday: true, wednesday: false, - thursday: false, + thursday: true, friday: false, }, }; diff --git a/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.html b/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.html index 5de161438a..0fe4d4c084 100644 --- a/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.html +++ b/packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.html @@ -264,6 +264,16 @@

Paramètres d'envoi de SMS pour votre structure

Vous devez sélectionner entre 1 et 2 jours de la semaine pour l'envoi de SMS

+

+ Vous devez sélectionner au moins 1 jour de la semaine + pour l'envoi de SMS +