feat(#138,#143,#144): fiche enfant admin, consentement photo et fix gestionnaire.
Squash merge develop → master. - #138 : modale enfant paysage, zone AM/scolarisation, liens responsables - #144 : persistance consent_photo à l'inscription enfant - #143 : masquer Supprimer sur la propre fiche gestionnaire 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,29 @@ 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 {
|
||||
final response = await http.delete(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.enfants}/$enfantId'),
|
||||
headers: await _headers(),
|
||||
);
|
||||
if (response.statusCode != 200 && response.statusCode != 204) {
|
||||
throw Exception(_extractErrorMessage(response.body, 'Erreur suppression enfant'));
|
||||
}
|
||||
}
|
||||
|
||||
/// AM dont la liste d'enfants actifs contient [enfantId] (API actuelle).
|
||||
static Future<AssistanteMaternelleModel?> findAmForEnfant(String enfantId) async {
|
||||
final ams = await getAssistantesMaternelles();
|
||||
for (final am in ams) {
|
||||
if (am.children.any((c) => c.id == enfantId)) return am;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static ParentModel _parentModelFromBody(String body) {
|
||||
|
||||
Reference in New Issue
Block a user