User.fromApi constructor

User.fromApi(
  1. Map<String, dynamic> jsonData
)

Implementation

factory User.fromApi(Map<String, dynamic> jsonData) {
  return User(
      id: jsonData['id'],
      gender: jsonData['gender'] ?? '',
      jobTitle: jsonData['jobTitle'] ?? '',
      username: jsonData['username'],
      password: jsonData['password'],
      firstName: jsonData['firstName'],
      surname: jsonData['surname'],
      name: jsonData['name'],
      phoneNumber: jsonData['phoneNumber'],
      baseUrl: jsonData['baseUrl'] ?? '',
      created: jsonData['created'],
      lastUpdated: jsonData['lastUpdated'],
      token: jsonData['token'],
      tokenType: jsonData['tokenType'],
      refreshToken: jsonData['refreshToken'],
      tokenExpiry: jsonData['tokenExpiry'],
      authType: jsonData['authType'],
      teiSearchOrganisationUnits:
          jsonData['teiSearchOrganisationUnits'].toString(),
      organisationUnits: jsonData['organisationUnits']
          .map<UserOrganisationUnit>((orgUnit) => UserOrganisationUnit(
              id: '${jsonData['id']}_${orgUnit['id']}',
              name: '${jsonData['id']}_${orgUnit['id']}',
              orgUnit: orgUnit['id'],
              parent:
                  orgUnit['parent'] != null ? orgUnit['parent']['id'] : null,
              user: jsonData['id'],
              type: 'DATA_VIEW',
              dirty: jsonData['dirty'] ?? false))
          .toList(),
      authorities: (jsonData['authorities'] ?? [])
          .map<UserAuthority>((authority) => UserAuthority(
              id: '${jsonData['id']}_$authority',
              name: '${jsonData['id']}_$authority',
              authority: authority,
              user: jsonData['id'],
              dirty: jsonData['dirty'] ?? false))
          .toList(),
      roles: (jsonData['userCredentials']?['userRoles'] ?? [])
          .map<UserRole>((role) => UserRole(
              id: '${jsonData['id']}_${role['id']}',
              name: role['name'],
              user: jsonData['id'],
              dirty: jsonData['dirty'] ?? true))
          .toList(),
      dataViewOrganisationUnits: jsonData['dataViewOrganisationUnits'],
      programs: jsonData['programs'] != null
          ? jsonData['programs'].toString()
          : null,
      dataSets: jsonData['datasets'] != null
          ? jsonData['datasets'].toString()
          : null,
      isLoggedIn: jsonData['isLoggedIn'] ?? false,
      dirty: jsonData['dirty'] ?? false);
}