Alert.fromMap constructor

Alert.fromMap(
  1. Map<String, dynamic> map
)

Implementation

factory Alert.fromMap(
  Map<String, dynamic> map,
) {
  map = {
    '\$id': "",
    '\$createdAt': "",
    '\$updatedAt': "",
    'monitorId': "",
    'projectId': "",
    'name': "",
    'status': "firing",
    'acknowledgedBy': "",
    'acknowledgedByName': "",
    'escalationId': "",
    'escalationStep': 0,
    'escalationRound': 0,
    'rules': [],
    'severity': "warning",
    'threshold': 0,
    'value': 0,
    'peak': 0,
    'type': "usage",
    'resourceType': "project",
    'resourceId': "",
    'notifications': 0,
    ...map,
  };

  return Alert(
    $id: map['\$id'].toString(),
    $createdAt: map['\$createdAt'].toString(),
    $updatedAt: map['\$updatedAt'].toString(),
    monitorId: map['monitorId'].toString(),
    projectId: map['projectId'].toString(),
    name: map['name'].toString(),
    status: enums.AlertStatus.values.firstWhere(
      (e) => e.value == map['status'],
    ),
    resolvedAt: map['resolvedAt']?.toString(),
    acknowledgedAt: map['acknowledgedAt']?.toString(),
    acknowledgedBy: map['acknowledgedBy'].toString(),
    acknowledgedByName: map['acknowledgedByName'].toString(),
    escalationId: map['escalationId'].toString(),
    escalationStep: map['escalationStep'],
    escalationRound: map['escalationRound'],
    escalatesAt: map['escalatesAt']?.toString(),
    rules: List.from(map['rules'] ?? []),
    severity: enums.MonitorSeverity.values.firstWhere(
      (e) => e.value == map['severity'],
    ),
    metric: map['metric'] != null
        ? enums.AlertMetric.values.firstWhere(
            (e) => e.value == map['metric'],
          )
        : null,
    comparator: map['comparator'] != null
        ? enums.AlertComparator.values.firstWhere(
            (e) => e.value == map['comparator'],
          )
        : null,
    threshold: map['threshold'].toDouble(),
    value: map['value'].toDouble(),
    peak: map['peak'].toDouble(),
    type: enums.MonitorType.values.firstWhere(
      (e) => e.value == map['type'],
    ),
    resourceType: enums.MonitorResourceType.values.firstWhere(
      (e) => e.value == map['resourceType'],
    ),
    resourceId: map['resourceId'].toString(),
    notifications: map['notifications'],
    latency: map['latency'],
    result: map['result'] != null
        ? enums.MonitorResult.values.firstWhere(
            (e) => e.value == map['result'],
          )
        : null,
  );
}