Global

Members

(constant) errorMessages :Object.<string, string>

Object containing all error messages used in the form
Type:
  • Object.<string, string>
Properties:
Name Type Description
INVALID_FIRST_NAME string "Le prénom n'est pas valide"
INVALID_LAST_NAME string "Le nom n'est pas valide"
INVALID_EMAIL string "L'email n'est pas valide"
EMAIL_ALREADY_EXISTS string "Cet email est déjà utilisé"
INVALID_ZIP string "Le code postal doit contenir 5 chiffres"
INVALID_CITY string "Le nom de la ville n'est pas valide"
UNDERAGE string "Vous devez avoir au moins 18 ans"
FUTURE_DATE string "La date de naissance ne peut pas être dans le futur"
INVALID_DATE string "La date de naissance est invalide",
BIRTHDATE_TOO_OLD string "La date de naissance est trop ancienne",
XSS_DETECTED string "Caractères interdits détectés"
SERVER_ERROR string "Serveur indisponible, réessayez plus tard"
Source:

Methods

calculateAge(p) → {number}

Calculate a person's age in years
Parameters:
Name Type Description
p object An object representing a person, implementing a birth Date parameter.
Source:
Returns:
The age in years of p.
Type
number

(async) createUser(person, existingEmails, apiPortopt, apiHostopt) → {Promise.<Object>}

Create a new user through backend API.
Parameters:
Name Type Attributes Description
person Object User object to create
existingEmails Array.<string> List of already registered emails
apiPort string | number <optional>
API port passed from app configuration
apiHost string <optional>
API host passed from app configuration
Source:
Throws:
Throws "EMAIL_ALREADY_EXISTS" or "SERVER_ERROR"
Type
Error
Returns:
Created user
Type
Promise.<Object>

(async) fetchUsers(apiPortopt, apiHostopt) → {Promise.<Array>}

Fetch all users from the API.
Parameters:
Name Type Attributes Description
apiPort string | number <optional>
API port passed from app configuration
apiHost string <optional>
API host passed from app configuration
Source:
Throws:
Throws "SERVER_ERROR" if request fails
Type
Error
Returns:
List of users
Type
Promise.<Array>

getApiBaseUrl(portOverrideopt, hostOverrideopt) → {string}

Build API base URL from host and port.
Parameters:
Name Type Attributes Description
portOverride string | number <optional>
Optional API port override
hostOverride string <optional>
Optional API host override
Source:
Returns:
API base URL
Type
string

getErrorMessage(key) → {string}

Retrieves the error message corresponding to a given key
Parameters:
Name Type Description
key string The error key (e.g., "INVALID_EMAIL", "UNDERAGE")
Source:
Returns:
The corresponding error message, or "Unknown error" if the key does not exist
Type
string

validateAge(birthDate) → {boolean}

Validates a person's age based on birth date. Rejects if under 18 years old, in the future, or too far in the past.
Parameters:
Name Type Description
birthDate Date Date of birth
Source:
Throws:
  • INVALID_DATE - If birthDate is not a valid Date object or cannot be parsed
    Type
    TypeError
  • FUTURE_DATE - If birthDate is in the future
    Type
    Error
  • BIRTHDATE_TOO_OLD - If birthDate is before 1900
    Type
    Error
  • UNDERAGE - If age < 18
    Type
    Error
Returns:
Returns true if age is 18 or older
Type
boolean

validateCity(city) → {boolean}

Validate a city name. Only letters, accents, spaces and hyphens are allowed. Rejects simple XSS patterns.
Parameters:
Name Type Description
city string The city name to validate
Source:
Throws:
  • INVALID_CITY if format is incorrect
    Type
    Error
  • XSS_DETECTED if a basic XSS pattern is detected
    Type
    Error
Returns:
true if valid
Type
boolean

validateEmail(email) → {boolean}

Validates an email address. Must be in standard email format.
Parameters:
Name Type Description
email string Email to validate
Source:
Throws:
Throws "INVALID_EMAIL" if email format is incorrect
Type
Error
Returns:
Returns true if email is valid
Type
boolean

validateName(name, type) → {boolean}

Validate a name (first or last) and return specific error messages
Parameters:
Name Type Description
name string The name to validate
type string "firstName" or "lastName" for custom error messages
Source:
Throws:
with message INVALID_FIRST_NAME or INVALID_LAST_NAME, XSS_DETECTED
Type
Error
Returns:
true if valid
Type
boolean

validatePerson(person) → {true}

Validates all parameters for a person
Parameters:
Name Type Description
person Object { birthDate, zip, identity, email }
Properties
Name Type Description
birthDate Date Date of birth
zip string French zip code (5 digits)
city string City name (letters, accents, espace, hyphens)
firstName string First name (letters, accents, hyphens)
lastName string Last name (letters, accents, hyphens)
email string Email address
Source:
Throws:
MISSING_PARAM, PARAM_TYPE_ERROR, UNDERAGE, INVALID_ZIP, INVALID_CITY, INVALID_FIRST_NAME, INVALID_LAST_NAME, XSS_DETECTED, INVALID_EMAIL
Type
Error
Returns:
if everything is valid
Type
true

validateZipCode(zip) → {boolean}

Validates a zip code. Must be exactly 5 digits.
Parameters:
Name Type Description
zip string Zip code
Source:
Throws:
Throws "INVALID_ZIP" if zip is invalid
Type
Error
Returns:
Returns true if zip is valid
Type
boolean