feat(#160): suppressions dashboard — poubelle, confirmations et sans_enfant.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -646,14 +646,93 @@ class UserService {
|
||||
return enrichEnfantParentNames(enfant);
|
||||
}
|
||||
|
||||
static Future<void> deleteEnfant(String enfantId) async {
|
||||
/// DELETE /enfants/:id?deleteDossier= — ticket #159 / #160.
|
||||
static Future<Map<String, dynamic>> deleteEnfant(
|
||||
String enfantId, {
|
||||
bool deleteDossier = false,
|
||||
}) async {
|
||||
final uri = Uri.parse(
|
||||
'${ApiConfig.baseUrl}${ApiConfig.enfants}/$enfantId',
|
||||
).replace(
|
||||
queryParameters: {
|
||||
'deleteDossier': deleteDossier ? 'true' : 'false',
|
||||
},
|
||||
);
|
||||
final response = await http.delete(uri, headers: await _headers());
|
||||
if (response.statusCode != 200 && response.statusCode != 204) {
|
||||
throw Exception(
|
||||
_extractErrorMessage(response.body, 'Erreur suppression enfant'),
|
||||
);
|
||||
}
|
||||
return _parseSuppressionBody(response.body);
|
||||
}
|
||||
|
||||
/// DELETE /dossiers/:numeroDossier — ticket #159 / #160.
|
||||
static Future<Map<String, dynamic>> deleteDossier(
|
||||
String numeroDossier,
|
||||
) async {
|
||||
final num = numeroDossier.trim();
|
||||
if (num.isEmpty) {
|
||||
throw Exception('Numéro de dossier manquant.');
|
||||
}
|
||||
final encoded = Uri.encodeComponent(num);
|
||||
final response = await http.delete(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.enfants}/$enfantId'),
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.dossiers}/$encoded'),
|
||||
headers: await _headers(),
|
||||
);
|
||||
if (response.statusCode != 200 && response.statusCode != 204) {
|
||||
throw Exception(_extractErrorMessage(response.body, 'Erreur suppression enfant'));
|
||||
throw Exception(
|
||||
_extractErrorMessage(response.body, 'Erreur suppression dossier'),
|
||||
);
|
||||
}
|
||||
return _parseSuppressionBody(response.body);
|
||||
}
|
||||
|
||||
/// Liste unifiée GET /dossiers — flags `sans_enfant` (#159).
|
||||
static Future<List<Map<String, dynamic>>> listDossiers({String? q}) async {
|
||||
final uri = Uri.parse('${ApiConfig.baseUrl}${ApiConfig.dossiers}')
|
||||
.replace(
|
||||
queryParameters: (q != null && q.trim().isNotEmpty)
|
||||
? {'q': q.trim()}
|
||||
: null,
|
||||
);
|
||||
final response = await http.get(uri, headers: await _headers());
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(
|
||||
_extractErrorMessage(response.body, 'Erreur chargement dossiers'),
|
||||
);
|
||||
}
|
||||
final decoded = jsonDecode(response.body);
|
||||
if (decoded is! List) return const [];
|
||||
return decoded
|
||||
.whereType<Map>()
|
||||
.map((e) => Map<String, dynamic>.from(e))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Map `numero_dossier` → `sans_enfant` (familles uniquement).
|
||||
static Future<Map<String, bool>> getSansEnfantByNumero() async {
|
||||
final rows = await listDossiers();
|
||||
final out = <String, bool>{};
|
||||
for (final row in rows) {
|
||||
final num = (row['numero_dossier'] ?? '').toString().trim();
|
||||
if (num.isEmpty) continue;
|
||||
final type = (row['type'] ?? '').toString().toLowerCase();
|
||||
if (type != 'famille') continue;
|
||||
out[num] = row['sans_enfant'] == true;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static Map<String, dynamic> _parseSuppressionBody(String body) {
|
||||
if (body.trim().isEmpty) return <String, dynamic>{};
|
||||
try {
|
||||
final decoded = jsonDecode(body);
|
||||
if (decoded is Map) {
|
||||
return Map<String, dynamic>.from(decoded);
|
||||
}
|
||||
} catch (_) {}
|
||||
return <String, dynamic>{};
|
||||
}
|
||||
|
||||
/// AM dont la liste d'enfants actifs contient [enfantId] (API actuelle).
|
||||
@@ -1224,22 +1303,18 @@ class UserService {
|
||||
return AppUser.fromJson(data);
|
||||
}
|
||||
|
||||
static Future<void> deleteUser(String userId) async {
|
||||
/// DELETE /users/:id — cascades métier #159 / #160.
|
||||
static Future<Map<String, dynamic>> deleteUser(String userId) async {
|
||||
final response = await http.delete(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.users}/$userId'),
|
||||
headers: await _headers(),
|
||||
);
|
||||
|
||||
if (response.statusCode != 200 && response.statusCode != 204) {
|
||||
final decoded = jsonDecode(response.body);
|
||||
if (decoded is Map<String, dynamic>) {
|
||||
final message = decoded['message'];
|
||||
if (message is List && message.isNotEmpty) {
|
||||
throw Exception(message.join(' - '));
|
||||
}
|
||||
throw Exception(_toStr(message) ?? 'Erreur suppression utilisateur');
|
||||
}
|
||||
throw Exception('Erreur suppression utilisateur');
|
||||
throw Exception(
|
||||
_extractErrorMessage(response.body, 'Erreur suppression utilisateur'),
|
||||
);
|
||||
}
|
||||
return _parseSuppressionBody(response.body);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user