Skip to content

Commit

Permalink
fix(domain/utilisateur): add better safeguard to getNombrePersonnesDa…
Browse files Browse the repository at this point in the history
…nsLogement()
  • Loading branch information
EmileRolley committed Oct 31, 2024
1 parent b27823e commit 8fa9055
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/domain/logement/logement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Logement {
this.dpe = this.AorB(input.dpe, this.dpe);
}

private undefinedToNull?(val): any {
private undefinedToNull?<T>(val: T | undefined): T | null {
return val === undefined ? null : val;
}

Expand Down
12 changes: 8 additions & 4 deletions src/domain/utilisateur/utilisateur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,15 @@ export class Utilisateur extends UtilisateurData {

/**
* Returns the total number of people in the household, including adults and
* children.
* children (see {@link UtilisateurData.logement}).
*
* @ensures The result to be in the range [1, +∞[.
*/
public getNombrePersonnesDansLogement?() {
const total = this.logement.nombre_adultes + this.logement.nombre_enfants;
return total || 1;
public getNombrePersonnesDansLogement?(): number {
return Math.max(
this.logement.nombre_adultes + this.logement.nombre_enfants,
1,
);
}

public setPassword?(password: string) {
Expand Down

0 comments on commit 8fa9055

Please sign in to comment.