mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-30 10:29:42 +00:00
Refactor validation handling in PersonEdit.vue
: Replace hasValidationError
and validationError
with hasViolation
and violationTitles
. Introduce hasViolationWithParameter
and violationTitlesWithParameter
for enhanced field validation. Update RequiredIdentifierConstraint
messages, improve API error mapping, and refine ValidationException
structure with violationsList
. Add tests and translations for identifier validation.
This commit is contained in:
@@ -25,14 +25,13 @@ export interface TransportExceptionInterface {
|
||||
name: string;
|
||||
}
|
||||
|
||||
// Strict : uniquement les clés déclarées dans M[K]
|
||||
export type ViolationFromMap<
|
||||
M extends Record<string, Record<string, unknown>>,
|
||||
> = {
|
||||
[K in Extract<keyof M, string>]: {
|
||||
propertyPath: K;
|
||||
title: string;
|
||||
parameters?: M[K]; // ← uniquement ces clés (pas d’extras)
|
||||
parameters?: M[K];
|
||||
type?: string;
|
||||
};
|
||||
}[Extract<keyof M, string>];
|
||||
@@ -53,18 +52,19 @@ export interface ValidationExceptionInterface<
|
||||
>,
|
||||
> extends Error {
|
||||
name: "ValidationException";
|
||||
/** Copie du payload serveur (utile pour logs/diagnostic) */
|
||||
problem: ValidationProblemFromMap<M>;
|
||||
/** Liste compacte "Titre: chemin" */
|
||||
/** Full server payload copy */
|
||||
problems: ValidationProblemFromMap<M>;
|
||||
/** A list of all violations, with property key */
|
||||
violationsList: ViolationFromMap<M>[];
|
||||
/** Compact list "Title: path" */
|
||||
violations: string[];
|
||||
/** Uniquement les titres */
|
||||
/** Only titles */
|
||||
titles: string[];
|
||||
/** Uniquement les chemins de propriété */
|
||||
/** Only property paths */
|
||||
propertyPaths: Extract<keyof M, string>[];
|
||||
/** Indexation par propriété (utile pour afficher par champ) */
|
||||
/** Indexing by property (useful for display by field) */
|
||||
byProperty: Record<Extract<keyof M, string>, string[]>;
|
||||
}
|
||||
|
||||
export class ValidationException<
|
||||
M extends Record<string, Record<string, unknown>> = Record<
|
||||
string,
|
||||
@@ -75,8 +75,9 @@ export class ValidationException<
|
||||
implements ValidationExceptionInterface<M>
|
||||
{
|
||||
public readonly name = "ValidationException" as const;
|
||||
public readonly problem: ValidationProblemFromMap<M>;
|
||||
public readonly problems: ValidationProblemFromMap<M>;
|
||||
public readonly violations: string[];
|
||||
public readonly violationsList: ViolationFromMap<M>[];
|
||||
public readonly titles: string[];
|
||||
public readonly propertyPaths: Extract<keyof M, string>[];
|
||||
public readonly byProperty: Record<Extract<keyof M, string>, string[]>;
|
||||
@@ -86,8 +87,9 @@ export class ValidationException<
|
||||
super(message);
|
||||
Object.setPrototypeOf(this, new.target.prototype);
|
||||
|
||||
this.problem = problem;
|
||||
this.problems = problem;
|
||||
|
||||
this.violationsList = problem.violations;
|
||||
this.violations = problem.violations.map(
|
||||
(v) => `${v.title}: ${v.propertyPath}`,
|
||||
);
|
||||
|
Reference in New Issue
Block a user