exportLogs static method

Future<String> exportLogs({
  1. DateTime? startDate,
  2. DateTime? endDate,
  3. String? userId,
  4. AuditEventType? eventType,
})

Export audit logs

Implementation

static Future<String> exportLogs({
  DateTime? startDate,
  DateTime? endDate,
  String? userId,
  AuditEventType? eventType,
}) async {
  var filtered = _events.where((event) {
    if (startDate != null && event.timestamp.isBefore(startDate)) {
      return false;
    }
    if (endDate != null && event.timestamp.isAfter(endDate)) {
      return false;
    }
    if (userId != null && event.userId != userId) {
      return false;
    }
    if (eventType != null && event.type != eventType) {
      return false;
    }
    return true;
  });

  return jsonEncode(filtered.map((e) => e.toJson()).toList());
}