Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions packages/backend/src/_migrations/1755033531923-manual-migration.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {
if (
domifaConfig().envId === "prod" ||
domifaConfig().envId === "preprod" ||
domifaConfig().envId === "local"
) {
appLogger.info("No down migration can be applied");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IsBoolean } from "class-validator";

export class ScheduleDto {
@IsBoolean()
monday: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ <h1 class="title">Paramètres d'envoi de SMS pour votre structure</h1>

<div class="col-12 my-2">
<fieldset>
<legend class=" ">
<legend class="required">
Quel(s) jour(s) souhaitez-vous envoyer les SMS (2 jours
par semaine maximum)
</legend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -173,6 +178,13 @@ export class StructuresSmsFormComponent implements OnInit, OnDestroy {
count++;
}
});
return count <= 2 ? null : { moreThanTwoDays: true };
if (count === 0) {
return { atLeastOneDay: true };
}
if (count > 2) {
return { moreThanTwoDays: true };
}

return null;
};
}