Skip to content

Commit 0a17ba1

Browse files
authored
fix(backend): 📅 fix update date of procurations (#3887)
1 parent cd92224 commit 0a17ba1

File tree

10 files changed

+28
-209
lines changed

10 files changed

+28
-209
lines changed

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ fileignoreconfig:
2626
- filename: packages/portail-admins/src/app/modules/admin-structures/utils/structure-filter-criteria.ts
2727
checksum: c54f1bf45a44280960869561243668e7a92713fb5265f008a95fc3fe66014bf1
2828
- filename: yarn.lock
29-
checksum: 391cb6ca45460de1264a5bb0717dbb870be35f011ae28d00b7bde2fe46ff2842
29+
checksum: 075be99c7d081e6dc58ad5b0a0382963b392355221e5f8cf7f18bdcab8dae794
3030
threshold: medium
3131
version: "1.0"

packages/backend/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
"sanitize-html": "^2.17.0",
102102
"sharp": "^0.34.0",
103103
"slug": "^9.1.0",
104-
"sort-object": "^3.0.3",
105104
"source-map-support": "^0.5.21",
106105
"striptags": "^3.2.0",
107106
"swagger-ui-express": "^5.0.1",
@@ -129,7 +128,6 @@
129128
"@types/nodemailer": "^6.4.17",
130129
"@types/nunjucks": "^3.2.6",
131130
"@types/passport-jwt": "^3.0.13",
132-
"@types/pdfkit": "^0.13.9",
133131
"@types/pino": "^7.0.5",
134132
"@types/pizzip": "^3.0.5",
135133
"@types/sanitize-html": "^2.16.0",

packages/backend/src/usagers/controllers/usager-options.controller.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { UsagerOptionsHistoryService } from "../services";
3333
import { ExpressResponse } from "../../util/express";
3434
import { isEqual } from "lodash";
3535

36-
import * as sortObj from "sort-object";
3736
import { usagerRepository } from "../../database";
3837
import {
3938
Usager,
@@ -121,7 +120,7 @@ export class UsagerOptionsController {
121120
);
122121
}
123122

124-
if (!isEqual(sortObj(usager.options.transfert), sortObj(transfertDto))) {
123+
if (!isEqual(usager.options.transfert, transfertDto)) {
125124
await this.usagerOptionsHistoryService.createOptionHistory(
126125
usager,
127126
user,
@@ -177,12 +176,7 @@ export class UsagerOptionsController {
177176
usager.options.procurations[i].dateFin
178177
);
179178

180-
if (
181-
isEqual(
182-
sortObj(usager.options.procurations[i]),
183-
sortObj(procurationsDto[i])
184-
)
185-
) {
179+
if (isEqual(usager.options.procurations[i], procurationsDto[i])) {
186180
needCreateHistory = false;
187181
}
188182
} else {

packages/common/src/usager-options/classes/MailDelegate.class.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createDate } from "../../_core";
22
import { IMailDelegate } from "../interfaces";
3+
import { endOfDay, isBefore } from "date-fns";
34

45
export class MailDelegate implements IMailDelegate {
56
public nom: string;
@@ -11,6 +12,11 @@ export class MailDelegate implements IMailDelegate {
1112
this.nom = options?.nom || "";
1213
this.dateDebut = createDate(options?.dateDebut);
1314
this.dateFin = createDate(options?.dateFin);
14-
this.isExpired = this.dateFin ? new Date() > this.dateFin : false;
15+
16+
if (!this?.dateFin) {
17+
this.isExpired = false;
18+
} else {
19+
this.isExpired = isBefore(this.dateFin, endOfDay(new Date()));
20+
}
1521
}
1622
}

packages/frontend/src/app/modules/admin-portail-usagers/components/manage-structure-information-form/manage-structure-information-form.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export class ManageStructureInformationFormComponent
244244
);
245245
}
246246

247-
private endDateAfterBeginDateValidator = (
247+
private readonly endDateAfterBeginDateValidator = (
248248
controls: AbstractControl
249249
): ValidationErrors | null => {
250250
const beginDateControl: AbstractControl | null = controls.get("startDate");

packages/frontend/src/app/modules/usager-dossier/components/decision-refus-form/decision-refus-form.component.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ import {
2121
import {
2222
formatDateToNgb,
2323
minDateToday,
24+
parseDateFromNgb,
2425
} from "../../../../shared/bootstrap-util";
2526
import { UsagerDecisionService } from "../../../usager-shared/services/usager-decision.service";
2627
import { Subscription } from "rxjs";
2728
import { NoWhiteSpaceValidator } from "../../../../shared";
28-
import {
29-
NgbDateCustomParserFormatter,
30-
CustomToastService,
31-
} from "../../../shared/services";
29+
import { CustomToastService } from "../../../shared/services";
3230
import { UsagerFormModel } from "../../../usager-shared/interfaces";
3331
import { MOTIFS_REFUS_LABELS } from "@domifa/common";
3432

@@ -56,7 +54,6 @@ export class DecisionRefusFormComponent implements OnInit, OnDestroy {
5654
private readonly formBuilder: UntypedFormBuilder,
5755
private readonly usagerDecisionService: UsagerDecisionService,
5856
private readonly router: Router,
59-
private readonly nbgDate: NgbDateCustomParserFormatter,
6057
private readonly toastService: CustomToastService
6158
) {
6259
this.loading = false;
@@ -108,9 +105,7 @@ export class DecisionRefusFormComponent implements OnInit, OnDestroy {
108105

109106
const formDatas: UsagerDecisionRefusForm = {
110107
...this.refusForm.value,
111-
dateFin: new Date(
112-
this.nbgDate.formatEn(this.refusForm.controls.dateFin.value)
113-
),
108+
dateFin: parseDateFromNgb(this.refusForm.controls.dateFin.value),
114109
};
115110

116111
this.setDecision(formDatas);

packages/frontend/src/app/modules/usager-dossier/components/decision-valide-form/decision-valide-form.component.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
UsagerLight,
2121
UsagerDecisionValideForm,
2222
} from "../../../../../_common/model";
23-
import { formatDateToNgb } from "../../../../shared";
23+
import { formatDateToNgb, parseDateFromNgb } from "../../../../shared";
2424
import { Decision, UsagerFormModel } from "../../../usager-shared/interfaces";
2525
import { UsagerDecisionService } from "../../../usager-shared/services/usager-decision.service";
2626
import {
@@ -130,17 +130,14 @@ export class DecisionValideFormComponent implements OnInit, OnDestroy {
130130

131131
this.subscription.add(
132132
this.valideForm.get("dateFin")?.valueChanges.subscribe((value) => {
133-
const dateDebut = new Date(
134-
this.nbgDate.formatEn(this.valideForm.get("dateDebut")?.value)
133+
const dateDebut = parseDateFromNgb(
134+
this.valideForm.get("dateDebut")?.value
135135
);
136136

137137
if (
138138
value !== null &&
139139
this.nbgDate.isValid(value) &&
140-
isBefore(
141-
new Date(this.nbgDate.formatEn(value)),
142-
subDays(addYears(dateDebut, 1), 1)
143-
)
140+
isBefore(parseDateFromNgb(value), subDays(addYears(dateDebut, 1), 1))
144141
) {
145142
this.showDurationWarning = true;
146143
} else {

packages/frontend/src/app/modules/usager-profil/components/_courriers/profil-procuration-courrier/profil-procuration-courrier-component.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import {
2525
} from "@ng-bootstrap/ng-bootstrap";
2626
import { MatomoTracker } from "ngx-matomo-client";
2727
import { Subscription } from "rxjs";
28-
import { CustomToastService } from "src/app/modules/shared/services/custom-toast.service";
29-
import { NgbDateCustomParserFormatter } from "src/app/modules/shared/services/date-formatter.service";
3028
import { DEFAULT_MODAL_OPTIONS } from "../../../../../../_common/model";
3129
import {
3230
endDateAfterBeginDateValidator,
@@ -36,12 +34,14 @@ import {
3634
minDateToday,
3735
minDateNaissance,
3836
formatDateToNgb,
37+
parseDateFromNgb,
3938
} from "../../../../../shared/bootstrap-util";
4039

4140
import { UsagerFormModel } from "../../../../usager-shared/interfaces";
4241

4342
import { UsagerOptionsService } from "../../../services/usager-options.service";
4443
import { UserStructure, UsagerOptionsProcuration } from "@domifa/common";
44+
import { CustomToastService } from "../../../../shared/services";
4545

4646
@Component({
4747
selector: "app-profil-procuration-courrier",
@@ -75,7 +75,6 @@ export class UsagersProfilProcurationCourrierComponent
7575

7676
constructor(
7777
private readonly formBuilder: UntypedFormBuilder,
78-
private readonly nbgDate: NgbDateCustomParserFormatter,
7978
private readonly toastService: CustomToastService,
8079
private readonly usagerOptionsService: UsagerOptionsService,
8180
private readonly matomo: MatomoTracker,
@@ -188,9 +187,9 @@ export class UsagersProfilProcurationCourrierComponent
188187
return {
189188
nom: procuration.nom,
190189
prenom: procuration.prenom,
191-
dateFin: this.nbgDate.formatEn(procuration.dateFin),
192-
dateDebut: this.nbgDate.formatEn(procuration.dateDebut),
193-
dateNaissance: this.nbgDate.formatEn(procuration.dateNaissance),
190+
dateFin: parseDateFromNgb(procuration.dateFin),
191+
dateDebut: parseDateFromNgb(procuration.dateDebut),
192+
dateNaissance: parseDateFromNgb(procuration.dateNaissance),
194193
};
195194
}
196195
);

packages/frontend/src/app/modules/usager-profil/components/_courriers/profil-transfert-courrier/profil-transfert-courrier-component.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ import {
2020
endDateAfterBeginDateValidator,
2121
formatDateToNgb,
2222
NoWhiteSpaceValidator,
23+
parseDateFromNgb,
2324
} from "../../../../../shared";
24-
import {
25-
NgbDateCustomParserFormatter,
26-
CustomToastService,
27-
} from "../../../../shared/services";
25+
import { CustomToastService } from "../../../../shared/services";
2826
import { UsagerFormModel } from "../../../../usager-shared/interfaces";
2927
import { UsagerOptionsService } from "../../../services/usager-options.service";
3028
import { UserStructure } from "@domifa/common";
@@ -53,7 +51,6 @@ export class UsagersProfilTransfertCourrierComponent implements OnDestroy {
5351

5452
constructor(
5553
private readonly formBuilder: UntypedFormBuilder,
56-
private readonly nbgDate: NgbDateCustomParserFormatter,
5754
private readonly toastService: CustomToastService,
5855
private readonly usagerOptionsService: UsagerOptionsService,
5956
private readonly modalService: NgbModal,
@@ -136,12 +133,8 @@ export class UsagersProfilTransfertCourrierComponent implements OnDestroy {
136133
const formValue = {
137134
actif: true,
138135
...this.transfertForm.value,
139-
dateFin: new Date(
140-
this.nbgDate.formatEn(this.transfertForm.controls.dateFin.value)
141-
),
142-
dateDebut: new Date(
143-
this.nbgDate.formatEn(this.transfertForm.controls.dateDebut.value)
144-
),
136+
dateFin: parseDateFromNgb(this.transfertForm.controls.dateFin.value),
137+
dateDebut: parseDateFromNgb(this.transfertForm.controls.dateDebut.value),
145138
};
146139

147140
this.loading = true;

0 commit comments

Comments
 (0)