petitspas/frontend/lib/models/reprise_dossier.dart
Julien Martin c26ed00374 fix(#112): préremplissage AM complet en reprise + lien login repositionné
Parse dates/places/consentement de façon robuste, rafraîchit l'étape 2 AM
et place « J'ai un numéro de dossier » sous « Créer un compte ».

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 17:29:31 +02:00

121 lines
3.9 KiB
Dart

import 'package:p_tits_pas/models/dossier_unifie.dart';
import 'package:p_tits_pas/utils/reprise_mapper.dart';
/// Réponse GET /auth/reprise-dossier. Tickets #111, #112.
class RepriseDossier {
final String id;
final String email;
final String? prenom;
final String? nom;
final String? telephone;
final String? adresse;
final String? ville;
final String? codePostal;
final String? numeroDossier;
final String role;
final String? photoUrl;
final String? genre;
final String? situationFamiliale;
final List<ParentDossier> parents;
final List<EnfantDossier> enfants;
final String? texteMotivation;
final bool consentementPhoto;
final String? dateNaissance;
final String? lieuNaissanceVille;
final String? lieuNaissancePays;
final String? numeroAgrement;
final String? nir;
final String? dateAgrement;
final int? nbMaxEnfants;
final int? placeDisponible;
final String? biographie;
const RepriseDossier({
required this.id,
required this.email,
this.prenom,
this.nom,
this.telephone,
this.adresse,
this.ville,
this.codePostal,
this.numeroDossier,
required this.role,
this.photoUrl,
this.genre,
this.situationFamiliale,
this.parents = const [],
this.enfants = const [],
this.texteMotivation,
this.consentementPhoto = false,
this.dateNaissance,
this.lieuNaissanceVille,
this.lieuNaissancePays,
this.numeroAgrement,
this.nir,
this.dateAgrement,
this.nbMaxEnfants,
this.placeDisponible,
this.biographie,
});
bool get isParent => role == 'parent';
bool get isAm => role == 'assistante_maternelle';
factory RepriseDossier.fromJson(Map<String, dynamic> json) {
final parentsRaw = json['parents'];
final parentsList = parentsRaw is List
? parentsRaw
.where((e) => e is Map)
.map((e) => ParentDossier.fromJson(Map<String, dynamic>.from(e as Map)))
.toList()
: <ParentDossier>[];
final enfantsRaw = json['enfants'];
final enfantsList = enfantsRaw is List
? enfantsRaw
.where((e) => e is Map)
.map((e) => EnfantDossier.fromJson(Map<String, dynamic>.from(e as Map)))
.toList()
: <EnfantDossier>[];
return RepriseDossier(
id: json['id']?.toString() ?? '',
email: json['email']?.toString() ?? '',
prenom: json['prenom']?.toString(),
nom: json['nom']?.toString(),
telephone: json['telephone']?.toString(),
adresse: json['adresse']?.toString(),
ville: json['ville']?.toString(),
codePostal: json['code_postal']?.toString(),
numeroDossier: json['numero_dossier']?.toString(),
role: json['role']?.toString() ?? '',
photoUrl: json['photo_url']?.toString(),
genre: json['genre']?.toString(),
situationFamiliale: json['situation_familiale']?.toString(),
parents: parentsList,
enfants: enfantsList,
texteMotivation: (json['texte_motivation'] ?? json['presentation_dossier'])
?.toString(),
consentementPhoto: RepriseMapper.optionalBool(json['consentement_photo']) ||
RepriseMapper.optionalBool(json['consent_photo']),
dateNaissance: RepriseMapper.optionalDateString(json['date_naissance']),
lieuNaissanceVille: json['lieu_naissance_ville']?.toString(),
lieuNaissancePays: json['lieu_naissance_pays']?.toString(),
numeroAgrement: (json['numero_agrement'] ?? json['numero_agrement_am'])
?.toString(),
nir: json['nir']?.toString(),
dateAgrement: RepriseMapper.optionalDateString(json['date_agrement']),
nbMaxEnfants: RepriseMapper.optionalInt(
json['nb_max_enfants'] ?? json['capacite_accueil'],
),
placeDisponible: RepriseMapper.optionalInt(
json['place_disponible'] ?? json['places_disponibles'],
),
biographie: (json['biographie'] ?? json['presentation'])?.toString(),
);
}
}