diff --git a/lib/models/user/user_info.dart b/lib/models/user/user_info.dart index 66d9f1ab6..f71c98893 100644 --- a/lib/models/user/user_info.dart +++ b/lib/models/user/user_info.dart @@ -1,5 +1,4 @@ -// ignore_for_file: talawa_api_doc, use_setters_to_change_properties -// ignore_for_file: talawa_good_doc_comments +// ignore_for_file: use_setters_to_change_properties import 'package:flutter/material.dart'; import 'package:hive/hive.dart'; @@ -27,11 +26,15 @@ class User extends HiveObject { factory User.fromJson(Map json1, {bool fromOrg = false}) { Map json; + Map? appUserProfile; if (fromOrg) { json = json1; + appUserProfile = json1; } else { json = json1['user'] as Map; + appUserProfile = json1['appUserProfile'] as Map?; } + return User( authToken: fromOrg ? ' ' : json1['accessToken'] as String?, refreshToken: fromOrg ? ' ' : json1['refreshToken'] as String?, @@ -41,24 +44,24 @@ class User extends HiveObject { lastName: json['lastName'] != null ? json['lastName'] as String? : null, email: json['email'] != null ? json['email'] as String? : null, image: json['image'] != null ? json['image'] as String? : null, - adminFor: json['adminFor'] != null - ? (json['adminFor'] as List?) - ?.map((e) => OrgInfo.fromJson(e as Map)) + adminFor: appUserProfile?['adminFor'] != null + ? (appUserProfile!['adminFor'] as List) + .map((e) => OrgInfo.fromJson(e as Map)) .toList() : null, - createdOrganizations: json['createdOrganizations'] != null - ? (json['createdOrganizations'] as List?) - ?.map((e) => OrgInfo.fromJson(e as Map)) + createdOrganizations: appUserProfile?['createdOrganizations'] != null + ? (appUserProfile!['createdOrganizations'] as List) + .map((e) => OrgInfo.fromJson(e as Map)) .toList() : null, joinedOrganizations: json['joinedOrganizations'] != null - ? (json['joinedOrganizations'] as List?) - ?.map((e) => OrgInfo.fromJson(e as Map)) + ? (json['joinedOrganizations'] as List) + .map((e) => OrgInfo.fromJson(e as Map)) .toList() : null, membershipRequests: json['membershipRequests'] != null - ? (json['membershipRequests'] as List?) - ?.map( + ? (json['membershipRequests'] as List) + .map( (e) => OrgInfo.fromJson( e as Map, memberRequest: true, @@ -68,7 +71,14 @@ class User extends HiveObject { : null, ); } - //Method to print the User details. + + /// Method to print the User details. + /// + /// **params**: + /// None + /// + /// **returns**: + /// None void print() { debugPrint('authToken: ${this.authToken}'); debugPrint('refreshToken: ${this.refreshToken}'); @@ -83,46 +93,101 @@ class User extends HiveObject { debugPrint('membershipRequests: ${this.membershipRequests}'); } + /// HiveField for authToken. @HiveField(0) String? authToken; + + /// HiveField for refreshToken. @HiveField(1) String? refreshToken; + + /// HiveField for userID. @HiveField(2) String? id; + + /// HiveField for user's first name. @HiveField(3) String? firstName; + + /// HiveField for user's last name. @HiveField(4) String? lastName; + + /// HiveField for user's Email. @HiveField(5) String? email; + + /// HiveField for user's avatar. @HiveField(6) String? image; + + /// /// HiveField for all organisations joined by user. @HiveField(7) List? joinedOrganizations = []; + + /// HiveField for all organisations created by user. @HiveField(8) List? createdOrganizations = []; + + /// HiveField for all organisations user is admin of. @HiveField(9) List? adminFor = []; + + /// HiveField for all organisations user has sent membership request. @HiveField(10) List? membershipRequests = []; + /// Method to updated joinedOrganisation list. + /// + /// **params**: + /// * `orgList`: List of organsaitions user has joined. + /// + /// **returns**: + /// None void updateJoinedOrg(List orgList) { this.joinedOrganizations = orgList; } + /// Method to updated createdOrganisation list. + /// + /// **params**: + /// * `orgList`: List of organsaitions user has created. + /// + /// **returns**: + /// None void updateCreatedOrg(List orgList) { this.createdOrganizations = orgList; } + /// Method to update membershipRequests List. + /// + /// **params**: + /// * `orgList`: List of organisations user have sent membership request. + /// + /// **returns**: + /// None void updateMemberRequestOrg(List orgList) { this.membershipRequests = [...membershipRequests!, ...orgList]; } + /// Method to update adminFor List. + /// + /// **params**: + /// * `orgList`: List of organisations user is admin of. + /// + /// **returns**: + /// None void updateAdminFor(List orgList) { this.adminFor = orgList; } - //Method to update the user details. + /// Method to update the user details. + /// + /// **params**: + /// * `details`: updated user Info/details + /// + /// **returns**: + /// None void update(User details) { this.firstName = details.firstName; this.lastName = details.lastName; diff --git a/lib/services/user_config.dart b/lib/services/user_config.dart index 359aa3637..047159587 100644 --- a/lib/services/user_config.dart +++ b/lib/services/user_config.dart @@ -89,7 +89,6 @@ class UserConfig { _currentUser = User(id: 'null', authToken: 'null'); return false; } - databaseFunctions.initClientNonAuth(); await sessionManager.refreshSession(); // generate access token @@ -102,16 +101,14 @@ class UserConfig { final List users = result.data!['users'] as List; final User userInfo = User.fromJson( users[0] as Map, - fromOrg: true, + fromOrg: false, ); userInfo.authToken = userConfig.currentUser.authToken; userInfo.refreshToken = userConfig.currentUser.refreshToken; userConfig.updateUser(userInfo); _currentOrg ??= _currentUser!.joinedOrganizations![0]; _currentOrgInfoController.add(_currentOrg!); - saveUserInHive(); - return true; } on Exception catch (e) { print(e); diff --git a/lib/utils/queries.dart b/lib/utils/queries.dart index db93bd917..256aa2651 100644 --- a/lib/utils/queries.dart +++ b/lib/utils/queries.dart @@ -23,7 +23,25 @@ class Queries { mutation{ signUp(data: {firstName: "$firstName", lastName: "$lastName", email: "$email", password: "$password"}) { - accessToken + appUserProfile{ + adminFor{ + _id + name + } + createdOrganizations{ + _id + name + image + description + userRegistrationRequired + creator{ + _id + firstName + lastName + image + } + } + } user{ _id firstName @@ -43,19 +61,6 @@ class Queries { image } } - createdOrganizations{ - _id - name - image - description - userRegistrationRequired - creator{ - _id - firstName - lastName - image - } - } membershipRequests{ organization{ _id @@ -71,11 +76,9 @@ class Queries { } } } - adminFor{ - _id - } } refreshToken + accessToken } } """; @@ -94,14 +97,12 @@ class Queries { return """ mutation { login(data: {email: "$email", password: "$password"}){ - accessToken - user{ - _id - firstName - lastName - email - image - joinedOrganizations{ + appUserProfile{ + adminFor{ + _id + name + } + createdOrganizations{ _id name image @@ -114,7 +115,14 @@ class Queries { image } } - createdOrganizations{ + } + user{ + _id + firstName + lastName + email + image + joinedOrganizations{ _id name image @@ -142,12 +150,9 @@ class Queries { } } } - adminFor{ - _id - } } refreshToken - + accessToken } } """; @@ -314,55 +319,60 @@ class Queries { String fetchUserInfo = ''' query Users(\$id: ID!){ users(where: { id: \$id }) { - _id - firstName - lastName - email - image - joinedOrganizations{ - _id - name - image - description - userRegistrationRequired - creator{ + appUserProfile{ + adminFor{ _id - firstName - lastName + name + } + createdOrganizations{ + _id + name image - } - + description + userRegistrationRequired + creator{ + _id + firstName + lastName + image + } + } } - createdOrganizations{ + user{ _id - name + firstName + lastName + email image - description - userRegistrationRequired - creator{ - _id - firstName - lastName - image - } - } - membershipRequests{ - organization{ + joinedOrganizations{ _id name image + description userRegistrationRequired creator{ _id firstName lastName image + } + } + membershipRequests{ + organization{ + _id + name + image + description + userRegistrationRequired + creator{ + _id + firstName + lastName + image + } } } } - adminFor{ - _id - } } } '''; diff --git a/pubspec.lock b/pubspec.lock index 6ae3f78e5..8b2e687ad 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -525,6 +525,38 @@ packages: url: "https://pub.dev" source: hosted version: "3.2.0" + geocoding: + dependency: "direct main" + description: + name: geocoding + sha256: e1dc0ac56666d9ed1d5a9ae5543ce9eb5986db6209cc7600103487d09192059c + url: "https://pub.dev" + source: hosted + version: "2.1.1" + geocoding_android: + dependency: transitive + description: + name: geocoding_android + sha256: "609db1d71bc364dd9d0616f72a41c01e0c74f3a3807efb85e0d5a67e57baf50f" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + geocoding_ios: + dependency: transitive + description: + name: geocoding_ios + sha256: "8f79e380abb640ef4d88baee8bb65390058c802601158d0813dc990b36b189d2" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + geocoding_platform_interface: + dependency: transitive + description: + name: geocoding_platform_interface + sha256: "8848605d307d844d89937cdb4b8ad7dfa880552078f310fa24d8a460f6dddab4" + url: "https://pub.dev" + source: hosted + version: "2.0.1" get_it: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 634cac312..b0803ac16 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,6 +44,8 @@ dependencies: flutter_speed_dial: ^7.0.0 flutter_svg: ^2.0.10+1 font_awesome_flutter: ^10.7.0 + geocoding: ^2.1.1 + geolocator: ^10.1.0 get_it: ^7.6.6 graphql_flutter: ^5.1.2 hive: ^2.2.3 diff --git a/test/model_tests/user/user_info_test.dart b/test/model_tests/user/user_info_test.dart index 5a2ef1761..0d9e7de24 100644 --- a/test/model_tests/user/user_info_test.dart +++ b/test/model_tests/user/user_info_test.dart @@ -69,11 +69,13 @@ final testDataNotFromOrg = { "accessToken": "randomAccessToken", "authToken": "randomAuthToken", "refreshToken": "randomRefreshToken", - "adminFor": testOrgList, - 'createdOrganizations': testOrgList, 'joinedOrganizations': testOrgList, 'membershipRequests': membershipRequestOrgList, }, + 'appUserProfile': { + 'createdOrganizations': testOrgList, + "adminFor": testOrgList, + }, }; void main() { diff --git a/test/service_tests/user_config_test.dart b/test/service_tests/user_config_test.dart index 3b281e335..74575c598 100644 --- a/test/service_tests/user_config_test.dart +++ b/test/service_tests/user_config_test.dart @@ -115,13 +115,30 @@ void main() async { final Map data = { 'users': [ { - '_id': '1234567890', - 'firstName': 'John', - 'lastName': 'Doe', - 'email': 'johndoe@example.com', - 'image': 'https://example.com/profile.jpg', - 'accessToken': 'exampleAccessToken', - 'refreshToken': 'exampleRefreshToken', + "user": { + "id": "1234567890", + "firstName": "ravidi", + "lastName": "sheikh", + "email": "ravidisheikh@test.com", + "image": "https://testimg.com", + "accessToken": "randomAccessToken", + "authToken": "randomAuthToken", + "refreshToken": "randomRefreshToken", + }, + 'appUserProfile': { + 'createdOrganizations': [ + { + "name": 'test_org', + "image": 'https://testimg.com', + } + ], + "adminFor": [ + { + "name": 'test_org1', + "image": 'https://testimg.com', + } + ], + }, } ], };