From 1c7874eb002d92f00400955bfc5dc1fead79c0ee Mon Sep 17 00:00:00 2001 From: "Yassine R." Date: Wed, 7 Aug 2024 01:36:55 +0300 Subject: [PATCH] fix(backend): fix update of status --- .../constants/USAGER_LIGHT_ATTRIBUTES.const.ts | 1 + .../services/usager/usagerRepository.service.ts | 13 ++++++++----- .../controllers/usagers-decision.controller.ts | 1 + .../backend/src/usagers/services/usagers.service.ts | 10 ++++++---- .../manage-usagers-page.component.ts | 4 +--- .../checkers/usagerStatutChecker.service.ts | 6 ++---- .../step-etat-civil/step-etat-civil.component.ts | 5 ++++- 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/packages/backend/src/database/services/usager/constants/USAGER_LIGHT_ATTRIBUTES.const.ts b/packages/backend/src/database/services/usager/constants/USAGER_LIGHT_ATTRIBUTES.const.ts index 6859062b42..37d55aa990 100644 --- a/packages/backend/src/database/services/usager/constants/USAGER_LIGHT_ATTRIBUTES.const.ts +++ b/packages/backend/src/database/services/usager/constants/USAGER_LIGHT_ATTRIBUTES.const.ts @@ -13,6 +13,7 @@ export const USAGER_LIGHT_ATTRIBUTES: (keyof Usager)[] = [ // "email", "decision", // "datePremiereDom", + "statut", "typeDom", "pinnedNote", // "entretien", diff --git a/packages/backend/src/database/services/usager/usagerRepository.service.ts b/packages/backend/src/database/services/usager/usagerRepository.service.ts index d005b39857..b82fd78f9f 100644 --- a/packages/backend/src/database/services/usager/usagerRepository.service.ts +++ b/packages/backend/src/database/services/usager/usagerRepository.service.ts @@ -200,11 +200,14 @@ async function findLastFiveCustomRef({ "structureId", ]) ) - .where(`statut = :statut and "structureId" = :structureId`, { - statut: "VALIDE", - structureId, - usagerRef, - }) + .where( + `statut = :statut and "structureId" = :structureId and ref != :usagerRef`, + { + statut: "VALIDE", + structureId, + usagerRef, + } + ) .orderBy({ "(decision->>'dateDecision')::timestamptz": "DESC" }) .limit(5) .getRawMany(); diff --git a/packages/backend/src/usagers/controllers/usagers-decision.controller.ts b/packages/backend/src/usagers/controllers/usagers-decision.controller.ts index 386fe3bc44..68a87be872 100644 --- a/packages/backend/src/usagers/controllers/usagers-decision.controller.ts +++ b/packages/backend/src/usagers/controllers/usagers-decision.controller.ts @@ -140,6 +140,7 @@ export class UsagersDecisionController { // On récupère la dernière décision usager.decision = usager.historique[usager.historique.length - 1]; + usager.statut = usager.decision.statut; usager.lastInteraction.dateInteraction = await getLastInteractionOut( usager, diff --git a/packages/backend/src/usagers/services/usagers.service.ts b/packages/backend/src/usagers/services/usagers.service.ts index 29fafb48be..6caf631f5f 100644 --- a/packages/backend/src/usagers/services/usagers.service.ts +++ b/packages/backend/src/usagers/services/usagers.service.ts @@ -43,7 +43,6 @@ export class UsagersService { usager.etapeDemande = ETAPE_RENDEZ_VOUS; usager.ref = await usagersCreator.findNextUsagerRef(user.structureId); usager.customRef = `${usager.ref}`; - usager.statut = "INSTRUCTION"; usager.decision = { uuid: uuidv4(), @@ -55,6 +54,7 @@ export class UsagersService { dateDebut: now, typeDom: "PREMIERE_DOM", }; + usager.statut = usager.decision.statut; usager.historique.push(usager.decision); usager.structureId = user.structureId; @@ -97,7 +97,6 @@ export class UsagersService { ? new Date(usager.decision.dateFin) : new Date(); } - usager.statut = "INSTRUCTION"; usager.decision = { uuid: uuidv4(), @@ -110,7 +109,7 @@ export class UsagersService { typeDom, motif: null, }; - + usager.statut = usager.decision.statut; // Ajout du précédent état dans l'historique usagerVisibleHistoryManager.addDecisionToVisibleHistory({ usager }); @@ -136,6 +135,7 @@ export class UsagersService { { lastInteraction: usager.lastInteraction, decision: usager.decision, + statut: usager.decision.statut, options: usager.options, historique: usager.historique, etapeDemande: usager.etapeDemande, @@ -186,8 +186,9 @@ export class UsagersService { usager.datePremiereDom = newDecision.dateDebut; } } - usager.statut = newDecision.statut; + usager.decision = newDecision as UsagerDecision; + usager.statut = usager.decision.statut; usager.decision.uuid = uuidv4(); usagerVisibleHistoryManager.addDecisionToVisibleHistory({ usager }); @@ -205,6 +206,7 @@ export class UsagersService { lastInteraction: usager.lastInteraction, customRef: usager.customRef, decision: usager.decision, + statut: usager.statut, historique: usager.historique, etapeDemande: usager.etapeDemande, typeDom: usager.typeDom, diff --git a/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.ts b/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.ts index 432b2dd92f..be4b8d9c98 100644 --- a/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.ts +++ b/packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.ts @@ -29,7 +29,6 @@ import { tap, withLatestFrom, } from "rxjs/operators"; -import { AuthService } from "src/app/modules/shared/services/auth.service"; import { fadeInOut, selectSearchPageLoadedUsagersData, @@ -50,7 +49,7 @@ import { Store } from "@ngrx/store"; import { ManageUsagersService } from "../../services/manage-usagers.service"; import { UserStructure } from "@domifa/common"; import { MatomoTracker } from "ngx-matomo-client"; -import { CustomToastService } from "../../../shared/services"; +import { AuthService, CustomToastService } from "../../../shared/services"; const AUTO_REFRESH_PERIOD = 300000; // 5 minutes @@ -381,7 +380,6 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy { const filterCriteria: UsagersFilterCriteria = { ...filters, - statut: null, }; const filteredUsagers = usagersFilter.filter( diff --git a/packages/frontend/src/app/modules/manage-usagers/components/usager-filter/services/checkers/usagerStatutChecker.service.ts b/packages/frontend/src/app/modules/manage-usagers/components/usager-filter/services/checkers/usagerStatutChecker.service.ts index 04e8c3f606..2ebbe94744 100644 --- a/packages/frontend/src/app/modules/manage-usagers/components/usager-filter/services/checkers/usagerStatutChecker.service.ts +++ b/packages/frontend/src/app/modules/manage-usagers/components/usager-filter/services/checkers/usagerStatutChecker.service.ts @@ -11,10 +11,8 @@ function check({ }: { usager: UsagerLight; } & Pick): boolean { - if (statut && statut !== "TOUS") { - if (statut !== usager.decision?.statut) { - return false; - } + if (statut && statut !== "TOUS" && statut !== usager.decision?.statut) { + return false; } return true; } diff --git a/packages/frontend/src/app/modules/usager-dossier/components/step-etat-civil/step-etat-civil.component.ts b/packages/frontend/src/app/modules/usager-dossier/components/step-etat-civil/step-etat-civil.component.ts index 3479551c33..4a6363abb1 100644 --- a/packages/frontend/src/app/modules/usager-dossier/components/step-etat-civil/step-etat-civil.component.ts +++ b/packages/frontend/src/app/modules/usager-dossier/components/step-etat-civil/step-etat-civil.component.ts @@ -63,6 +63,7 @@ export class StepEtatCivilComponent next: (usager: Usager) => { this.usager = new UsagerFormModel(usager); this.initForm(); + this.listenNameChanges(); }, error: () => { this.toastService.error("Le dossier recherché n'existe pas"); @@ -73,8 +74,11 @@ export class StepEtatCivilComponent } else { this.usager = new UsagerFormModel(); this.initForm(); + this.listenNameChanges(); } + } + public listenNameChanges() { const lastNameChanges = this.usagerForm.get("nom")!.valueChanges; const firstNameChanges = this.usagerForm.get("prenom")!.valueChanges; @@ -86,7 +90,6 @@ export class StepEtatCivilComponent }) ); } - public isDuplicateName(): void { if ( this.usagerForm.controls.nom.value &&