79d00ba001
Four small Dio-backed API classes mirroring the server's actual
contract (verified against internal/api/admin_*.go):
- Requests/Quarantine return flat lists; Users/Invites are enveloped
({"users": [...]}, {"invites": [...]}) and unwrap here
- setAutoApprove sends {auto_approve: bool} — different from the
response field name auto_approve_requests
- resetPassword takes admin-supplied {password: string}, returns 204
- Invite create takes optional {note: string}; expiry is server-fixed
at 24h
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
33 lines
1.0 KiB
Dart
33 lines
1.0 KiB
Dart
import 'package:dio/dio.dart';
|
|
|
|
import '../../models/invite.dart';
|
|
|
|
class AdminInvitesApi {
|
|
AdminInvitesApi(this._dio);
|
|
final Dio _dio;
|
|
|
|
/// GET /api/admin/invites → `{"invites": [...]}`. Envelope unwrapped.
|
|
Future<List<Invite>> list() async {
|
|
final r = await _dio.get<Map<String, dynamic>>('/api/admin/invites');
|
|
final raw = (r.data?['invites'] as List?) ?? const [];
|
|
return raw
|
|
.map((e) => Invite.fromJson((e as Map).cast<String, dynamic>()))
|
|
.toList(growable: false);
|
|
}
|
|
|
|
/// POST /api/admin/invites — body is optional `{"note": "..."}`.
|
|
/// Server hardcodes the 24h TTL; admins cannot configure expiry.
|
|
/// Returns the bare invite (not enveloped).
|
|
Future<Invite> create({String? note}) async {
|
|
final r = await _dio.post<Map<String, dynamic>>(
|
|
'/api/admin/invites',
|
|
data: {if (note != null && note.isNotEmpty) 'note': note},
|
|
);
|
|
return Invite.fromJson(r.data ?? const {});
|
|
}
|
|
|
|
Future<void> revoke(String token) async {
|
|
await _dio.delete<void>('/api/admin/invites/$token');
|
|
}
|
|
}
|