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" |
USER_NOT_FOUND |
string | "Utilisateur introuvable" |
USER_DELETED |
string | "Utilisateur supprimé avec succès" |
- 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, existingEmailsopt) → {Promise.<Object>}
Creates a new user via the API.
Performs a local email uniqueness check before sending the request,
and correctly interprets backend 400 status codes for duplicate emails.
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
person |
Object | The user object to create.
Properties
|
||||||||||||||||||||||||||||||
existingEmails |
Array.<string> |
<optional> |
[] | List of currently registered emails to validate against locally. |
- Source:
Throws:
-
Throws "EMAIL_ALREADY_EXISTS" if the email is taken, or "SERVER_ERROR" for other failures.
- Type
- Error
Returns:
The created user object returned by the API.
- Type
- Promise.<Object>
(async) deleteUser(userId) → {Promise.<void>}
Deletes a specific user via the API using their ID.
Parameters:
| Name | Type | Description |
|---|---|---|
userId |
number | string | The unique identifier of the user to delete. |
- Source:
Throws:
-
Throws "SERVER_ERROR" if the deletion fails (e.g., network error, 404, or 500).
- Type
- Error
Returns:
Resolves when the user is successfully deleted.
- Type
- Promise.<void>
(async) fetchUsers() → {Promise.<Array.<{id: number, firstName: string, lastName: string, email: string, birthDate: string, zip: string, city: string}>>}
Fetches all users from the API.
Adapts the response format whether it comes from the mock API (JSONPlaceholder)
or the custom Python backend database.
- Source:
Throws:
-
Throws "SERVER_ERROR" if the network request fails or server crashes.
- Type
- Error
Returns:
List of mapped users.
- Type
- Promise.<Array.<{id: number, firstName: string, lastName: string, email: string, birthDate: string, zip: string, city: string}>>
getApiBase() → {string}
Determines the base API URL depending on environment variables.
If `VITE_USE_MOCK_API` is set to 'true', it returns the JSONPlaceholder URL.
Otherwise, it uses `VITE_API_BASE_URL` or defaults to 'http://127.0.0.1:8000'.
- Source:
Returns:
The base URL for API requests.
- 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
|
- 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