feat(#140): dashboard admin ch.6 — fiche parent, enfants, affiliation
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>
This commit is contained in:
@@ -1,18 +1,40 @@
|
||||
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});
|
||||
ParentModel({
|
||||
required this.user,
|
||||
this.childrenCount = 0,
|
||||
this.children = const [],
|
||||
});
|
||||
|
||||
factory ParentModel.fromJson(Map<String, dynamic> json) {
|
||||
final userJson = json['user'] ?? 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 = json['parentChildren'] as List?;
|
||||
|
||||
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?.length ?? 0,
|
||||
childrenCount: children.isNotEmpty ? children.length : (links?.length ?? 0),
|
||||
children: children,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user