Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class InteractionsDeletor {
}: {
interaction: CommonInteraction;
usager: Usager;
structure: Pick<Structure, "id" | "sms" | "telephone" | "portailUsager">;
structure: Pick<
Structure,
"id" | "sms" | "telephone" | "portailUsager" | "timeZone"
>;
}): Promise<Usager> {
const direction = interactionsTypeManager.getDirection(interaction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Generate SMS Schedule Date", () => {
structure.sms.schedule.tuesday = true;

const expectedDate = utcToZonedTime(
generateScheduleSendDate(structure, monday),
generateScheduleSendDate(structure, monday, "Europe/Paris"),
"Europe/Paris"
);

Expand All @@ -38,22 +38,27 @@ describe("Generate SMS Schedule Date", () => {
structure.sms.schedule.tuesday = false;
structure.sms.schedule.friday = true;
const expectedDate = utcToZonedTime(
generateScheduleSendDate(structure, friday),
generateScheduleSendDate(structure, friday, "Europe/Paris"),
"Europe/Paris"
);

expect(expectedDate).toEqual(fridayRef);
});
it("Receive after 19:00, send next week", () => {
const friday = new Date("2024-05-10T21:05:00.000Z");
const fridayRef = new Date("2024-05-17T19:00:00.000Z");
const expectedDate = utcToZonedTime(
new Date("2024-05-17T19:00:00.000Z"),
"America/Cayenne"
);
structure.sms.schedule.tuesday = false;
structure.sms.schedule.friday = true;
const expectedDate = utcToZonedTime(
generateScheduleSendDate(structure, friday),
"Europe/Paris"

const scheduledDate = generateScheduleSendDate(
structure,
friday,
"America/Cayenne"
);

expect(expectedDate).toEqual(fridayRef);
expect(scheduledDate).toEqual(expectedDate);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Structure } from "@domifa/common";
import { Structure, TimeZone } from "@domifa/common";
import { Day, nextDay } from "date-fns";
import { utcToZonedTime } from "date-fns-tz";

const weekDays = [
"sunday",
Expand All @@ -13,7 +14,8 @@ const weekDays = [

export const generateScheduleSendDate = (
structure: Pick<Structure, "sms">,
dateReference: Date = new Date()
dateReference: Date = new Date(),
timeZone: TimeZone
): Date => {
const days: string[] = Object.keys(structure.sms.schedule).filter(
(day: string) => structure.sms.schedule[day]
Expand All @@ -27,7 +29,7 @@ export const generateScheduleSendDate = (
: nextDay(dateReference, nextDayId as Day);

nextDate.setUTCHours(19, 0, 0);
return nextDate;
return utcToZonedTime(nextDate, timeZone);
};

function getNextClosestDay(days: string[], dateReference: Date): number {
Expand Down
10 changes: 7 additions & 3 deletions packages/backend/src/modules/sms/services/message-sms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ export class MessageSmsService {

public async createSmsInteraction(
usager: Usager,
structure: Pick<Structure, "id" | "sms" | "telephone">,
structure: Pick<Structure, "id" | "sms" | "telephone" | "timeZone">,
interaction: CommonInteraction
) {
const scheduledDate = generateScheduleSendDate(structure, new Date());
const scheduledDate = generateScheduleSendDate(
structure,
new Date(),
structure.timeZone
);

const smsReady: MessageSms = await messageSmsRepository.findSmsOnHold({
usagerRef: usager.ref,
Expand Down Expand Up @@ -134,7 +138,7 @@ export class MessageSmsService {
usager,
}: {
interaction: CommonInteraction;
structure: Pick<Structure, "id" | "sms" | "telephone">;
structure: Pick<Structure, "id" | "sms" | "telephone" | "timeZone">;
usager: Usager;
}): Promise<void> {
// 1. Vérifier l'activation des SMS par la structure
Expand Down
39 changes: 21 additions & 18 deletions packages/frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Title } from "@angular/platform-browser";
import { Event, NavigationEnd, Router } from "@angular/router";
import { NgbModal, NgbModalRef } from "@ng-bootstrap/ng-bootstrap";
import { MatomoTracker } from "ngx-matomo-client";
import { filter, firstValueFrom, Subscription } from "rxjs";
import { filter, Subscription, switchMap } from "rxjs";
import { AuthService } from "src/app/modules/shared/services/auth.service";

import { DEFAULT_MODAL_OPTIONS } from "../_common/model";
Expand Down Expand Up @@ -119,7 +119,8 @@ export class AppComponent implements OnInit, OnDestroy {
this.authService.currentUserSubject.subscribe({
next: (user: UserStructure | null) => {
this.me = user;
if (!this.me || this.modalService.hasOpenModals()) {
console.log(user?.acceptTerms);
if (!user || this.modalService.hasOpenModals()) {
return;
}

Expand Down Expand Up @@ -216,22 +217,24 @@ export class AppComponent implements OnInit, OnDestroy {
this.loading = true;

this.subscription.add(
this.authService.acceptTerms().subscribe({
next: () => {
this.submitted = false;
this.loading = false;
this.toastService.success(
"Merci, vous pouvez continuer votre navigation"
);
this.closeModals();
firstValueFrom(this.authService.isAuth());
this.refresh();
},
error: () => {
this.loading = false;
this.toastService.error("Veuillez cocher les 2 cases pour continuer");
},
})
this.authService
.acceptTerms()
.pipe(switchMap(() => this.authService.isAuth()))
.subscribe({
next: () => {
this.submitted = false;
this.loading = false;
this.toastService.success(
"Merci, vous pouvez continuer votre navigation"
);
this.closeModals();
this.refresh();
},
error: () => {
this.loading = false;
this.toastService.error("Veuillez accepter les CGU pour continuer");
},
})
);
}

Expand Down
1 change: 0 additions & 1 deletion packages/frontend/src/assets/files/news.json
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,6 @@
"La page de statistiques a été mise à jour avec l'ajout de nouveaux chiffres."
]
},

{
"type": "new",
"categorie": "Conditions générales d'utilisation",
Expand Down
Loading