Back: PATCH /parents/:id/fiche, attach/detach enfant, GET /enfants enrichi. Front: modale parent éditable, onglet Enfants, fiche enfant, UserService. Couvre doc 28 §6.1–6.2 ; tickets liés #115 #116 #130 #131 #137 #138. Hors scope: fiche AM (#131), création admin (#129). Co-authored-by: Cursor <cursoragent@cursor.com>
41 lines
1.2 KiB
Dart
41 lines
1.2 KiB
Dart
import 'package:p_tits_pas/models/parent_child_summary.dart';
|
|
import 'package:p_tits_pas/models/user.dart';
|
|
|
|
class ParentModel {
|
|
final AppUser user;
|
|
final int childrenCount;
|
|
final List<ParentChildSummary> children;
|
|
|
|
ParentModel({
|
|
required this.user,
|
|
this.childrenCount = 0,
|
|
this.children = const [],
|
|
});
|
|
|
|
factory ParentModel.fromJson(Map<String, dynamic> json) {
|
|
final userJson = Map<String, dynamic>.from(json['user'] ?? json);
|
|
if (json['numero_dossier'] != null && userJson['numero_dossier'] == null) {
|
|
userJson['numero_dossier'] = json['numero_dossier'];
|
|
}
|
|
final user = AppUser.fromJson(userJson);
|
|
|
|
final children = <ParentChildSummary>[];
|
|
final links = json['parentChildren'] as List?;
|
|
if (links != null) {
|
|
for (final link in links) {
|
|
if (link is Map<String, dynamic> && link['child'] is Map<String, dynamic>) {
|
|
children.add(
|
|
ParentChildSummary.fromJson(link['child'] as Map<String, dynamic>),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
return ParentModel(
|
|
user: user,
|
|
childrenCount: children.isNotEmpty ? children.length : (links?.length ?? 0),
|
|
children: children,
|
|
);
|
|
}
|
|
}
|