Skip to content

Commit 6679f04

Browse files
committed
fix(backend): fixing reviews
1 parent 6ba95bb commit 6679f04

File tree

3 files changed

+36
-41
lines changed

3 files changed

+36
-41
lines changed

packages/backend/src/_migrations/1755033531923-manual-migration.ts

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,41 @@
1-
import { MigrationInterface } from "typeorm";
1+
import { MigrationInterface, QueryRunner } from "typeorm";
22
import { domifaConfig } from "../config";
3-
import { structureRepository } from "../database";
4-
import { StructureSmsParams } from "@domifa/common";
53
import { appLogger } from "../util";
64

75
export class ManualMigration1755033531923 implements MigrationInterface {
86
name: string = "ManualMigration1755033531923";
9-
public async up(): Promise<void> {
10-
const emailList = [];
7+
public async up(queryRunner: QueryRunner): Promise<void> {
118
if (
129
domifaConfig().envId === "prod" ||
1310
domifaConfig().envId === "preprod" ||
1411
domifaConfig().envId === "local"
1512
) {
1613
appLogger.info("Starting migration: Updating structures SMS schedules");
14+
await queryRunner.query(`
15+
UPDATE structure
16+
SET sms = sms || '{"schedule": {"monday": false, "tuesday": true, "wednesday": false, "thursday": true, "friday": false}}'::jsonb
17+
WHERE
18+
(sms->>'enabledByStructure')::boolean = TRUE
19+
AND (sms->'schedule'->>'friday')::boolean = FALSE
20+
AND (sms->'schedule'->>'monday')::boolean = FALSE
21+
AND (sms->'schedule'->>'thursday')::boolean = FALSE
22+
AND (sms->'schedule'->>'tuesday')::boolean = FALSE
23+
AND (sms->'schedule'->>'wednesday')::boolean = FALSE;
24+
`);
1725

18-
const structures = await structureRepository.find({
19-
select: {
20-
id: true,
21-
email: true,
22-
sms: true,
23-
},
24-
});
26+
const count = await queryRunner.query(`
27+
SELECT COUNT(*) FROM structure
28+
WHERE
29+
(sms->>'enabledByStructure')::boolean = TRUE
30+
AND (sms->'schedule'->>'friday')::boolean = FALSE
31+
AND (sms->'schedule'->>'monday')::boolean = FALSE
32+
AND (sms->'schedule'->>'thursday')::boolean = FALSE
33+
AND (sms->'schedule'->>'tuesday')::boolean = FALSE
34+
AND (sms->'schedule'->>'wednesday')::boolean = FALSE;
35+
`);
2536

26-
const structuresWithoutSmsSchedule = structures.filter(
27-
(s) => !Object.values(s.sms?.schedule).some((value) => value === true)
28-
);
29-
30-
// Process each structure record
31-
for (const structure of structuresWithoutSmsSchedule) {
32-
const smsParams: StructureSmsParams = {
33-
...structure.sms,
34-
schedule: {
35-
...structure.sms.schedule,
36-
tuesday: true,
37-
thursday: true,
38-
},
39-
};
40-
41-
await structureRepository.update(
42-
{
43-
id: structure.id,
44-
},
45-
{
46-
sms: smsParams,
47-
}
48-
);
49-
50-
emailList.push(structure.email);
51-
}
37+
console.log(count);
5238
appLogger.info("Migration end");
53-
appLogger.info("Liste des emails des structures à contacter:", emailList);
5439
}
5540
}
5641

packages/backend/src/modules/structures/services/structureCreator.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ async function createStructure(structureDto: StructureDto) {
112112
enabledByStructure: false,
113113
schedule: {
114114
monday: false,
115-
tuesday: false,
115+
tuesday: true,
116116
wednesday: false,
117-
thursday: false,
117+
thursday: true,
118118
friday: false,
119119
},
120120
};

packages/frontend/src/app/modules/structures/components/structures-sms-form/structures-sms-form.component.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ <h1 class="title">Paramètres d'envoi de SMS pour votre structure</h1>
264264
Vous devez sélectionner entre 1 et 2 jours de la semaine
265265
pour l'envoi de SMS
266266
</p>
267+
<p
268+
*ngIf="
269+
submitted || structureSmsForm?.errors?.atLeastOneDay
270+
"
271+
class="invalid-feedback"
272+
id="sender-details-errors"
273+
>
274+
Vous devez sélectionner au moins 1 jour de la semaine
275+
pour l'envoi de SMS
276+
</p>
267277
</div>
268278
</fieldset>
269279
</div>

0 commit comments

Comments
 (0)