Skip to content

Commit

Permalink
fix(backend): fix update of status
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Aug 6, 2024
1 parent 72f9849 commit 1c7874e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const USAGER_LIGHT_ATTRIBUTES: (keyof Usager)[] = [
// "email",
"decision",
// "datePremiereDom",
"statut",
"typeDom",
"pinnedNote",
// "entretien",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions packages/backend/src/usagers/services/usagers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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;
Expand Down Expand Up @@ -97,7 +97,6 @@ export class UsagersService {
? new Date(usager.decision.dateFin)
: new Date();
}
usager.statut = "INSTRUCTION";

usager.decision = {
uuid: uuidv4(),
Expand All @@ -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 });

Expand All @@ -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,
Expand Down Expand Up @@ -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 });
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
tap,
withLatestFrom,
} from "rxjs/operators";
import { AuthService } from "src/app/modules/shared/services/auth.service";
import {
fadeInOut,
selectSearchPageLoadedUsagersData,
Expand All @@ -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

Expand Down Expand Up @@ -381,7 +380,6 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {

const filterCriteria: UsagersFilterCriteria = {
...filters,
statut: null,
};

const filteredUsagers = usagersFilter.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ function check({
}: {
usager: UsagerLight;
} & Pick<UsagersFilterCriteria, "statut">): boolean {
if (statut && statut !== "TOUS") {
if (statut !== usager.decision?.statut) {
return false;
}
if (statut && statut !== "TOUS" && statut !== usager.decision?.statut) {
return false;
}
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;

Expand All @@ -86,7 +90,6 @@ export class StepEtatCivilComponent
})
);
}

public isDuplicateName(): void {
if (
this.usagerForm.controls.nom.value &&
Expand Down

0 comments on commit 1c7874e

Please sign in to comment.