All checks were successful
continuous-integration/drone/push Build is passing
Add a new module to enable accommodations reservation  Reviewed-on: #188
22 lines
596 B
TypeScript
22 lines
596 B
TypeScript
import { LenConstraint } from "../api/ServerApi";
|
|
|
|
/**
|
|
* Check if a constraint was respected or not
|
|
*
|
|
* @returns An error message appropriate for the constraint
|
|
* violation, if any, or undefined otherwise
|
|
*/
|
|
export function checkConstraint(
|
|
constraint: LenConstraint,
|
|
value: string | undefined
|
|
): string | undefined {
|
|
value = value ?? "";
|
|
if (value.length < constraint.min)
|
|
return `Veuillez indiquer au moins ${constraint.min} caractères !`;
|
|
|
|
if (value.length > constraint.max)
|
|
return `Veuillez indiquer au maximum ${constraint.max} caractères !`;
|
|
|
|
return undefined;
|
|
}
|