Skip to content

Commit

Permalink
fix: transfert expiration #1501
Browse files Browse the repository at this point in the history
  • Loading branch information
Toub committed Jul 5, 2021
1 parent 44f3c90 commit 31971cf
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 64 deletions.
19 changes: 4 additions & 15 deletions packages/backend/src/_common/model/usager/UsagerOptions.type.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { UsagerOptionsHistorique } from "./UsagerOptionsHistorique.type";
import { UsagerOptionsProcuration } from "./UsagerOptionsProcuration.type";
import { UsagerOptionsTransfert } from "./UsagerOptionsTransfert.type";

export type UsagerOptions = {
transfert: {
actif: boolean;
nom?: string;
adresse?: string;
dateDebut?: Date | null;
dateFin?: Date | null;
};
procuration: {
actif: boolean;
nom?: string;
prenom?: string;
dateFin?: Date | null;
dateDebut?: Date | null;
dateNaissance?: string | null;
};
transfert: UsagerOptionsTransfert;
procuration: UsagerOptionsProcuration;
npai: {
actif: boolean;
dateDebut?: Date | null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type UsagerOptionsProcuration = {
actif: boolean;
nom?: string;
prenom?: string;
dateFin?: Date | null;
dateDebut?: Date | null;
dateNaissance?: Date | string | null;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type UsagerOptionsTransfert = {
actif: boolean;
nom?: string;
adresse?: string;
dateDebut?: Date | null;
dateFin?: Date | null;
};
4 changes: 3 additions & 1 deletion packages/backend/src/_common/model/usager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export * from "./UsagerDecisionOrientation.type";
export * from "./UsagerDecisionStatut.type";
export * from "./UsagerDoc.type";
export * from "./UsagerEntretien.type";
export * from "./UsagerImport.type";
export * from "./UsagerLastInteractions.type";
export * from "./UsagerLight.type";
export * from "./UsagerOptions.type";
export * from "./UsagerOptionsHistorique.type";
export * from "./UsagerOptionsProcuration.type";
export * from "./UsagerOptionsTransfert.type";
export * from "./UsagerPreferenceContact.type";
export * from "./UsagerRaisonDemande.type";
export * from "./UsagerRdv.type";
export * from "./UsagerSexe.type";
export * from "./UsagerImport.type";
export * from "./UsagerTypeDom.type";
15 changes: 14 additions & 1 deletion packages/backend/src/interactions/interactions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "../database";
import { AppAuthUser, AppUser, Usager, UsagerLight } from "../_common/model";
import { Interactions, InteractionType } from "../_common/model/interaction";
import { UsagerOptionsTransfert } from "../_common/model/usager";
import { InteractionDto } from "./interactions.dto";

@Injectable()
Expand Down Expand Up @@ -162,7 +163,7 @@ function buildNewInteraction({
}

// Transfert actif: on le précise dans le contenu
if (usager.options.transfert.actif) {
if (isTransfertActifMaintenant(usager.options.transfert)) {
newInteraction.content =
"Courrier transféré à : " +
usager.options.transfert.nom +
Expand Down Expand Up @@ -197,3 +198,15 @@ function buildNewInteraction({

return { usager, newInteraction };
}

export function isTransfertActifMaintenant(
transfert: UsagerOptionsTransfert
): boolean {
if (transfert.actif) {
const debut = new Date(transfert.dateDebut).getTime();
const fin = new Date(transfert.dateFin).getTime();
const now = new Date().getTime();
return debut < now && fin > now;
}
return false;
}
19 changes: 4 additions & 15 deletions packages/frontend/src/_common/model/usager/UsagerOptions.type.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { UsagerOptionsHistorique } from "./UsagerOptionsHistorique.type";
import { UsagerOptionsProcuration } from "./UsagerOptionsProcuration.type";
import { UsagerOptionsTransfert } from "./UsagerOptionsTransfert.type";

export type UsagerOptions = {
transfert: {
actif: boolean;
nom: string;
adresse: string;
dateDebut?: Date;
dateFin?: Date;
};
procuration: {
actif: boolean;
nom?: string;
prenom?: string;
dateFin?: Date;
dateDebut?: Date;
dateNaissance?: Date;
};
transfert: UsagerOptionsTransfert;
procuration: UsagerOptionsProcuration;
npai: {
actif: boolean;
dateDebut?: Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type UsagerOptionsProcuration = {
actif: boolean;
nom?: string;
prenom?: string;
dateFin?: Date | null;
dateDebut?: Date | null;
dateNaissance?: Date | string | null;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type UsagerOptionsTransfert = {
actif: boolean;
nom?: string;
adresse?: string;
dateDebut?: Date | null;
dateFin?: Date | null;
};
8 changes: 5 additions & 3 deletions packages/frontend/src/_common/model/usager/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
export * from "./Usager.type";
export * from "./UsagerAyantDroit.type";
export * from "./UsagerDecision.type";
export * from "./UsagerDecisionMotif.type";
export * from "./UsagerDecisionStatut.type";
export * from "./UsagerDoc.type";
export * from "./UsagerEntretien.type";
export * from "./UsagerImport.type";
export * from "./UsagerLastInteractions.type";
export * from "./UsagerLight.type";
export * from "./UsagerOptions.type";
export * from "./UsagerOptionsHistorique.type";
export * from "./UsagerOptionsProcuration.type";
export * from "./UsagerOptionsTransfert.type";
export * from "./UsagerPreferenceContact.type";
export * from "./UsagerRaisonDemande.type";
export * from "./UsagerRdv.type";
export * from "./UsagerSexe.type";
export * from "./UsagerAyantDroit.type";
export * from "./UsagerTypeDom.type";
export * from "./UsagerDecisionMotif.type";
export * from "./UsagerImport.type";
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class SetInteractionOutFormComponent implements OnInit, OnDestroy {
public procuration: boolean; // Mandataire = true / domicilié = false

public displayProcuration() {
return isProcurationActifMaintenant(this.usager);
return isProcurationActifMaintenant(this.usager.options.procuration);
}

private subscription = new Subscription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@ import {
TemplateRef,
ViewChild,
} from "@angular/core";

import { NgbModal, NgbModalOptions } from "@ng-bootstrap/ng-bootstrap";
import { MatomoTracker } from "ngx-matomo";
import { ToastrService } from "ngx-toastr";
import { fadeInOut, fadeInOutSlow } from "src/app/shared/animations";
import { AppUser, UsagerLight } from "../../../../../../_common/model";
import {
AppUser,
UsagerLight,
UsagerOptionsProcuration,
UsagerOptionsTransfert,
} from "../../../../../../_common/model";
import {
InteractionForApi,
InteractionType,
} from "../../../../../../_common/model/interaction";
import { interactionsLabels } from "../../../interactions.labels";
import { isProcurationActifMaintenant } from "../../../services";
import { InteractionService } from "../../../services/interaction.service";
import { isTransfertActifMaintenant } from "../../../services/transfert.service";
import { UsagerFormModel } from "../../form/UsagerFormModel";
import {
UsagersFilterCriteria,
UsagersFilterCriteriaDernierPassage,
UsagersFilterCriteriaSortValues,
UsagersFilterCriteriaStatut,
} from "../usager-filter";

@Component({
Expand Down Expand Up @@ -87,6 +92,13 @@ export class ManageUsagersTableComponent implements OnInit {
this.today = new Date();
}

public isProcurationActifMaintenant(procuration: UsagerOptionsProcuration) {
return isProcurationActifMaintenant(procuration);
}
public isTransfertActifMaintenant(transfert: UsagerOptionsTransfert) {
return isTransfertActifMaintenant(transfert);
}

public setSingleInteraction(
usager: UsagerFormModel,
type: InteractionType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

<div
class="label-info label-yellow"
*ngIf="usager.options.transfert.actif"
*ngIf="isTransfertActifMaintenant(usager.options.transfert)"
[ngbTooltip]="transfertActif"
>
<ng-template #transfertActif>
Expand All @@ -135,7 +135,7 @@

<div
class="label-info label-yellow"
*ngIf="usager.options.procuration.actif"
*ngIf="isProcurationActifMaintenant(usager.options.procuration)"
[ngbTooltip]="procurationActif"
>
<ng-template #procurationActif>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
minDateNaissance,
} from "src/app/shared/bootstrap-util";
import { regexp } from "src/app/shared/validators";
import { AppUser, UsagerLight, UserRole } from "../../../../../_common/model";
import {
AppUser,
UsagerLight,
UsagerOptionsProcuration,
UserRole,
} from "../../../../../_common/model";
import { InteractionType } from "../../../../../_common/model/interaction";
import { StructureDocTypesAvailable } from "../../../../../_common/model/structure-doc";
import { ETAPES_DEMANDE_URL } from "../../../../../_common/model/usager/constants";
Expand Down Expand Up @@ -395,6 +400,10 @@ export class UsagersProfilComponent implements OnInit {
}
}

public isProcurationActifMaintenant(procuration: UsagerOptionsProcuration) {
return isProcurationActifMaintenant(procuration);
}

public setInteraction(type: InteractionType, procuration?: boolean) {
const interaction: {
content?: string;
Expand All @@ -411,7 +420,7 @@ export class UsagersProfilComponent implements OnInit {
this.matomo.trackEvent("test-nouveau-profil", "gros-icones", type, 1);

if (type.substring(type.length - 3) === "Out") {
if (isProcurationActifMaintenant(this.usager)) {
if (isProcurationActifMaintenant(this.usager.options.procuration)) {
if (typeof procuration === "undefined") {
this.typeInteraction = type;
this.modalService.open(this.distributionConfirm);
Expand Down
22 changes: 6 additions & 16 deletions packages/frontend/src/app/modules/usagers/interfaces/options.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import {
UsagerOptionsProcuration,
UsagerOptionsTransfert,
} from "../../../../_common/model";
import { UsagerOptions } from "./../../../../_common/model/usager/UsagerOptions.type";
import { HistoriqueOptions } from "./historique-options";

export class Options implements UsagerOptions {
public transfert: {
actif: boolean;
adresse: string | null;
dateDebut: Date | null;
dateFin: Date | null;
nom: string | null;
};

public procuration: {
actif: boolean;
dateDebut: Date | null;
dateFin: Date | null;
dateNaissance: Date | null;
nom: string;
prenom: string;
};
public transfert: UsagerOptionsTransfert;
public procuration: UsagerOptionsProcuration;

public npai: {
actif: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { UsagerLight } from "../../../../_common/model";
import { UsagerOptionsProcuration } from "../../../../_common/model";

export function isProcurationActifMaintenant(
usager: Pick<UsagerLight, "options">
procuration: UsagerOptionsProcuration
): boolean {
if (usager.options.procuration.actif) {
const debut = new Date(usager.options.procuration.dateDebut).getTime();
const fin = new Date(usager.options.procuration.dateFin).getTime();
if (procuration.actif) {
const debut = new Date(procuration.dateDebut).getTime();
const fin = new Date(procuration.dateFin).getTime();
const now = new Date().getTime();
return debut < now && fin > now;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { UsagerOptionsTransfert } from "../../../../_common/model/usager";

export function isTransfertActifMaintenant(
transfert: UsagerOptionsTransfert
): boolean {
if (transfert.actif) {
const debut = new Date(transfert.dateDebut).getTime();
const fin = new Date(transfert.dateFin).getTime();
const now = new Date().getTime();
return debut < now && fin > now;
}
return false;
}

0 comments on commit 31971cf

Please sign in to comment.