toMap method

Map<String, dynamic> toMap()

Implementation

Map<String, dynamic> toMap() {
  Map<String, dynamic> map = {};

  if (id != null) {
    map['_id'] = id;
  }
  if (name != null) {
    map['name'] = name;
  }
  if (emails != null) {
    map['emails'] = emails
            ?.where((json) => json != null)
            ?.map((email) => email.toMap())
            ?.toList() ??
        [];
  }
  if (status != null) {
    map['status'] = status;
  }
  if (statusConnection != null) {
    map['statusConnection'] = statusConnection;
  }
  if (username != null) {
    map['username'] = username;
  }
  if (utcOffset != null) {
    map['utcOffset'] = utcOffset;
  }
  if (active != null) {
    map['active'] = active;
  }
  if (roles != null) {
    map['roles'] = roles?.where((json) => json != null)?.toList() ?? [];
  }
  if (settings != null) {
    map['settings'] = settings != null
        ? (settings!['preferences'] != null
            ? {'preferences': settings!['preferences']!.toMap()}
            : {'preferences': {}})
        : null;
  }
  if (avatarUrl != null) {
    map['avatarUrl'] = avatarUrl;
  }
  if (customFields != null) {
    map['customFields'] = customFields;
  }
  if (success != null) {
    map['success'] = success;
  }

  return map;
}