fix(#138): enrichir les noms des responsables sur GET enfant.
GET /enfants/:id ne joint pas parent.user ; on complète les noms via GET parent pour l'affichage des liens (ex. ouverture depuis la fiche AM). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -460,7 +460,40 @@ class UserService {
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(_extractErrorMessage(response.body, 'Erreur chargement enfant'));
|
||||
}
|
||||
return EnfantAdminModel.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
final enfant = EnfantAdminModel.fromJson(
|
||||
jsonDecode(response.body) as Map<String, dynamic>,
|
||||
);
|
||||
// GET /enfants/:id ne joint pas toujours parent.user → noms manquants.
|
||||
return enrichEnfantParentNames(enfant);
|
||||
}
|
||||
|
||||
/// Complète [parentName] via GET parent quand l'API n'a pas fourni le nested user.
|
||||
static Future<EnfantAdminModel> enrichEnfantParentNames(
|
||||
EnfantAdminModel enfant,
|
||||
) async {
|
||||
final links = enfant.parentLinks;
|
||||
if (links.isEmpty) return enfant;
|
||||
if (links.every((l) => (l.parentName ?? '').trim().isNotEmpty)) {
|
||||
return enfant;
|
||||
}
|
||||
|
||||
final enriched = await Future.wait(
|
||||
links.map((link) async {
|
||||
if ((link.parentName ?? '').trim().isNotEmpty) return link;
|
||||
final id = link.parentId.trim();
|
||||
if (id.isEmpty) return link;
|
||||
try {
|
||||
final parent = await getParent(id);
|
||||
final name = parent.user.fullName.trim();
|
||||
if (name.isEmpty) return link;
|
||||
return link.copyWith(parentName: name);
|
||||
} catch (_) {
|
||||
return link;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
return enfant.copyWith(parentLinks: enriched);
|
||||
}
|
||||
|
||||
static Future<EnfantAdminModel> updateEnfant({
|
||||
@@ -475,7 +508,10 @@ class UserService {
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(_extractErrorMessage(response.body, 'Erreur mise à jour enfant'));
|
||||
}
|
||||
return EnfantAdminModel.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
final enfant = EnfantAdminModel.fromJson(
|
||||
jsonDecode(response.body) as Map<String, dynamic>,
|
||||
);
|
||||
return enrichEnfantParentNames(enfant);
|
||||
}
|
||||
|
||||
static Future<void> deleteEnfant(String enfantId) async {
|
||||
|
||||
Reference in New Issue
Block a user