Skip to content

Commit

Permalink
fix(frontend): fix search of date birth
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Dec 19, 2024
1 parent 6dedb85 commit 62f1510
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const userStructureSecurityRepository = myDataSource
"uuid" | "userId" | "temporaryTokens" | "eventsHistory"
>
> {
return this.createQueryBuilder("user_structure_security")
return await this.createQueryBuilder("user_structure_security")
.where(`"temporaryTokens"->>'token' = :tokenValue`, {
tokenValue,
})
Expand Down Expand Up @@ -51,7 +51,7 @@ export const userStructureSecurityRepository = myDataSource
clearAllEvents,
});

return this.update(
return await this.update(
{ userId },
attributes
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export class AdminStructuresController {
user_structure.prenom,
user_structure.email,
user_structure.role,
user_structure.verified,
user_structure."lastLogin",
user_structure."createdAt",
user_structure.uuid,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { UsagersFilterCriteria } from "../UsagersFilterCriteria";
import { format } from "date-fns";
import { format, isValid, parseISO } from "date-fns";
import { UsagerLight } from "../../../../../../_common/model";
import { UsagerProcuration } from "../../../../usager-shared/interfaces/UsagerProcuration.interface";
import { UsagerAyantDroit } from "@domifa/common";

const validateBirthDate = (date?: Date | string): string | undefined => {
if (!date) return undefined;
const parsedDate = typeof date === "string" ? parseISO(date) : date;
return !isValid(parsedDate) ? undefined : format(parsedDate, "dd/MM/yyyy");
};

export const getAttributes = (
usager: UsagerLight,
{
Expand All @@ -12,21 +18,16 @@ export const getAttributes = (
) => {
let attributes = [];
if (searchStringField === "DATE_NAISSANCE") {
const dateNaissance =
typeof usager.dateNaissance === "string"
? new Date(usager.dateNaissance)
: null;

attributes = dateNaissance ? [format(dateNaissance, "dd/MM/yyyy")] : [];

usager.ayantsDroits.forEach((ad: UsagerAyantDroit) => {
const dateNaissanceAd =
typeof ad.dateNaissance === "string"
? new Date(ad.dateNaissance)
: null;
if (dateNaissanceAd) {
attributes.push(format(dateNaissanceAd, "dd/MM/yyyy"));
}
const attributes: string[] = [];

if (usager.dateNaissance) {
const formattedDate = validateBirthDate(usager.dateNaissance);
if (formattedDate) attributes.push(formattedDate);
}

usager.ayantsDroits.forEach((ad) => {
const formattedDate = validateBirthDate(ad.dateNaissance);
if (formattedDate) attributes.push(formattedDate);
});

return attributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const setUsagerInformation = (usager: Usager): any => {
historique: [],
options: new Options(usager.options),
rdv: null,
dateNaissance: new Date(usager?.dateNaissance),
entretien: null,
};
};
1 change: 1 addition & 0 deletions packages/portail-admins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"class-validator": "^0.14.1",
"date-fns": "^2.30.0",
"file-saver": "^2.0.5",
"google-libphonenumber": "^3.2.40",
"ngx-matomo-client": "^5.0.4",
"redux": "^4.2.1",
"rimraf": "^5.0.10",
Expand Down
2 changes: 2 additions & 0 deletions packages/portail-admins/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
import {
CUSTOM_ELEMENTS_SCHEMA,
ErrorHandler,
LOCALE_ID,
NgModule,
NO_ERRORS_SCHEMA,
} from "@angular/core";
Expand Down Expand Up @@ -54,6 +55,7 @@ registerLocaleData(localeFr, "fr");
MATOMO_INJECTORS,
],
providers: [
{ provide: LOCALE_ID, useValue: "fr" },
{ provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true },
{
multi: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,55 @@
<div class="row pb-5" *ngIf="structure">
<div class="col-md-6">
<div class="row">
<div class="col-12">
<h2>Informations</h2>
</div>
<div class="col-12">
<h2>Informations</h2>
</div>

<div class="col-6 my-1 align-self-center">
<p class="my-1"><b>Nom : </b>{{ structure.nom }}</p>
<p class="my-1">
<b>Type de structure :</b> {{ structure.structureType }}
</p>
<p class="my-1"><b>Département :</b> {{ structure.departement }}</p>
<p class="col-md-4 reponses">
<span class="question">Nom</span>
<span class="valeur">{{ structure.nom }}</span>
</p>
<p class="col-md-4 reponses">
<span class="question">Type de structure</span>
<span class="valeur">{{ structure.structureType }}</span>
</p>
<p class="col-md-4 reponses">
<span class="question">Département</span>
<span class="valeur">{{ structure.departement }}</span>
</p>

<p class="my-1">
<b>Adresse : </b>
</p>
<ul>
<li>{{ structure.adresse }}</li>
<li>{{ structure.codePostal }}, {{ structure.ville }}</li>
</ul>
<p></p>
<p class="my-1">
<b> Coordonnées de la structure: </b>
</p>
<ul>
<li>{{ structure.email }}</li>
<li>{{ structure.telephone }}</li>
</ul>
<!-- Adresse -->
<p class="col-md-4 reponses">
<span class="question">Adresse</span>
<span class="valeur">{{ structure.adresse }}</span>
</p>
<p class="col-md-4 reponses">
<span class="question">Ville</span>
<span class="valeur"
>{{ structure.codePostal }}, {{ structure.ville }}</span
>
</p>

<p class="my-1">
<b>Responsable de la structure: </b>
</p>
<ul>
<li>
{{ structure?.responsable?.nom }}
{{ structure?.responsable?.prenom }}
</li>
<li>{{ structure?.responsable?.fonction }}</li>
</ul>
</div>
</div>
</div>
<!-- Coordonnées -->
<p class="col-md-4 reponses">
<span class="question">Email</span>
<span class="valeur">{{ structure.email }}</span>
</p>
<p class="col-md-4 reponses">
<span class="question">Téléphone</span>
<span class="valeur">{{
structure.telephone | formatInternationalPhoneNumber
}}</span>
</p>

<!-- Responsable -->
<p class="col-md-4 reponses">
<span class="question">Nom du responsable</span>
<span class="valeur"
>{{ structure?.responsable?.nom }}
{{ structure?.responsable?.prenom }}</span
>
</p>
<p class="col-md-4 reponses">
<span class="question">Fonction du responsable</span>
<span class="valeur">{{ structure?.responsable?.fonction }}</span>
</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TableHeadSortComponent } from "../../../shared/components/table-head-so
import { SortArrayPipe } from "../../../shared/pipes/sort-array.pipe";
import { StructureService } from "../../services/structure.service";
import { STRUCTURE_MOCK } from "../../STRUCTURE_MOCK.const";
import { FormatInternationalPhoneNumberPipe } from "../../../../shared/utils/formatInternationalPhoneNumber.pipe";

describe("StructureInfoComponent", () => {
let component: StructureInfoComponent;
Expand All @@ -22,6 +23,7 @@ describe("StructureInfoComponent", () => {
SortArrayPipe,
HttpClientTestingModule,
RouterModule.forRoot([]),
FormatInternationalPhoneNumberPipe,
],
providers: [StructureService],
}).compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,22 @@ <h2>Utilisateurs enregistrés: {{ users.length }} utilisateurs</h2>
</th>
<th scope="col">
<app-table-head-sort
sortKey="lastLogin"
sortKey="verified"
[(sortValue)]="sortValue"
[(currentKey)]="currentKey"
columnName="Statut"
>
</app-table-head-sort>
</th>
<th scope="col">
<app-table-head-sort
sortKey="lastLogin"
[(sortValue)]="sortValue"
[(currentKey)]="currentKey"
columnName="Dernière connexion"
>
</app-table-head-sort>
</th>
<th scope="col">
<app-table-head-sort
sortKey="role"
Expand All @@ -67,11 +76,18 @@ <h2>Utilisateurs enregistrés: {{ users.length }} utilisateurs</h2>
<td>{{ user.createdAt | date : "d MMMM y" }}</td>
<td>
<p *ngIf="user.verified">✅ Compte actif</p>
<p *ngIf="!user.verified && user.lastLogin">
❌ Inactif depuis plus de 2 mois<br />Dernière connexion le
{{ user.lastLogin | date : "d MMMM y" }}
</p>
<p class="fw-bold" *ngIf="!user.verified && !user.lastLogin">
<p *ngIf="!user.verified">❌ Compte non vérifié</p>
</td>
<td>
<ng-container *ngIf="user.lastLogin">
<p>
{{ user.lastLogin | date : "dd/MM/yyyy" }}
<b *ngIf="user.lastLogin < twoMonthsAgo">
<br />❌ Inactif depuis plus de 2 mois<br />
</b>
</p>
</ng-container>
<p class="fw-bold" *ngIf="!user.lastLogin">
❌ Compte jamais utilisé
</p>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
UserStructureWithSecurity,
} from "../../services/structure.service";
import { environment } from "../../../../../environments/environment";
import { subMonths } from "date-fns";

@Component({
selector: "app-users",
Expand All @@ -16,6 +17,7 @@ export class UsersComponent implements OnInit {
public users: UserStructureWithSecurity[] = [];
public sortValue: SortValues = "asc";
public currentKey = "id";
public twoMonthsAgo = subMonths(new Date(), 2);

public readonly frontendUrl = environment.frontendUrl;
public readonly USER_ROLES_LABELS: { [key in UserStructureRole]: string } = {
Expand All @@ -34,7 +36,12 @@ export class UsersComponent implements OnInit {
ngOnInit(): void {
this.subscription.add(
this.structureService.getUsers(this.structure.id).subscribe((users) => {
this.users = users;
this.users = users.map((user) => {
if (user?.lastLogin) {
user.lastLogin = new Date(user.lastLogin);
}
return user;
});
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { StructureRoutingModule } from "./structure-routing.module";
import { UsersComponent } from "./components/users/users.component";
import { SortArrayPipe } from "../shared/pipes/sort-array.pipe";
import { StructureInfoComponent } from "./components/structure-info/structure-info.component";
import { FormatInternationalPhoneNumberPipe } from "../../shared/utils/formatInternationalPhoneNumber.pipe";

@NgModule({
declarations: [
Expand All @@ -20,6 +21,7 @@ import { StructureInfoComponent } from "./components/structure-info/structure-in
imports: [
CommonModule,
NgbModule,
FormatInternationalPhoneNumberPipe,
SharedModule,
FontAwesomeModule,
TableHeadSortComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Pipe, PipeTransform } from "@angular/core";
import { Telephone } from "@domifa/common";
import { PhoneNumberFormat, PhoneNumberUtil } from "google-libphonenumber";

@Pipe({ name: "formatInternationalPhoneNumber", standalone: true })
export class FormatInternationalPhoneNumberPipe implements PipeTransform {
public transform(telephone: Telephone): string {
const phoneUtil = PhoneNumberUtil.getInstance();
if (!telephone) {
return "Non renseigné";
}

if (
telephone?.numero === "" ||
!telephone?.numero ||
!telephone?.countryCode
) {
return "Non renseigné";
}

try {
const numero = phoneUtil.parse(
telephone.numero,
telephone.countryCode.toLowerCase()
);
if (!phoneUtil.isValidNumber(numero) || !numero) {
return "Non renseigné";
}
return phoneUtil.format(numero, PhoneNumberFormat.INTERNATIONAL);
} catch (error) {
return "Numéro introuvable";
}
}
}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4067,6 +4067,7 @@ __metadata:
eslint-plugin-no-lookahead-lookbehind-regexp: "npm:^0.3.0"
eslint-plugin-prettier: "npm:^5.2.1"
file-saver: "npm:^2.0.5"
google-libphonenumber: "npm:^3.2.40"
jest: "npm:^29.7.0"
jest-preset-angular: "npm:^14.1.1"
lint-staged: "npm:^15.2.10"
Expand Down Expand Up @@ -16652,6 +16653,13 @@ __metadata:
languageName: node
linkType: hard

"google-libphonenumber@npm:^3.2.40":
version: 3.2.40
resolution: "google-libphonenumber@npm:3.2.40"
checksum: 10/787627acb2fd3467dcf294e17184ece3b67aa3250e361e12fbbab9c0b6aaf0e5b75e97943ba152f2321581aadceb4180f41299ec56461543fd6f3021f54e6363
languageName: node
linkType: hard

"gopd@npm:^1.0.1":
version: 1.0.1
resolution: "gopd@npm:1.0.1"
Expand Down

0 comments on commit 62f1510

Please sign in to comment.