Skip to content

Commit b5c3749

Browse files
authored
Исправил десериализацию профиля сотрудника (#618)
1 parent fc7886b commit b5c3749

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

lib/core/models/profile/employee/employee_data.dart

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,12 @@ class EmployeeData extends UserData {
6666
factory EmployeeData.fromJson(JsonMap json) => EmployeeData.withUserData(
6767
userData: UserData.fromJson(json),
6868
syncId: json[_EmployeeDataJsonKeys.syncId]! as String,
69-
profiles: [
70-
for (final item in json[_EmployeeDataJsonKeys.profiles]! as List)
71-
EmployeeProfile.fromJson(item as JsonMap),
72-
],
73-
);
74-
75-
factory EmployeeData.fromCurrentProfileJson(JsonMap json) =>
76-
EmployeeData.withUserData(
77-
userData: UserData.fromJson(json),
78-
syncId: json[_EmployeeDataJsonKeys.syncId]! as String,
79-
profiles: [EmployeeProfile.fromJson(json)],
69+
profiles: json.containsKey(_EmployeeDataJsonKeys.profiles)
70+
? [
71+
for (final item
72+
in json[_EmployeeDataJsonKeys.profiles]! as List)
73+
EmployeeProfile.fromJson(item as JsonMap),
74+
]
75+
: [EmployeeProfile.fromJson(json)],
8076
);
8177
}

lib/core/providers/implementations/profile/user_data_provider_impl.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,17 @@ class UserDataProviderImpl implements UserDataProvider {
5050

5151
final jsonMap = jsonDecode(userInfo) as Map<String, dynamic>;
5252

53-
return switch (userType) {
54-
_student => StudentData.fromJson(jsonMap),
55-
_employee => EmployeeData.fromCurrentProfileJson(jsonMap),
56-
_ => UserData.fromJson(jsonMap),
57-
};
53+
try {
54+
return switch (userType) {
55+
_student => StudentData.fromJson(jsonMap),
56+
_employee => EmployeeData.fromJson(jsonMap),
57+
_ => UserData.fromJson(jsonMap),
58+
};
59+
} catch (e, stackTrace) {
60+
_loggerService.logError(e, stackTrace, information: [jsonMap.toString()]);
61+
}
62+
63+
return null;
5864
}
5965

6066
@override

lib/core/services/implementations/profile/profile_of_current_user_service_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ProfileOfCurrentUserServiceImpl implements ProfileOfCurrentUserService {
4343
(jsonMap as JsonMap)[ProfilesStrings.type] == ProfilesStrings.student
4444
? StudentData.fromJson(jsonMap)
4545
: jsonMap[ProfilesStrings.type] == ProfilesStrings.employee
46-
? EmployeeData.fromCurrentProfileJson(jsonMap)
46+
? EmployeeData.fromJson(jsonMap)
4747
: null;
4848
} catch (e, stackTrace) {
4949
_loggerService.logError(e, stackTrace, information: [jsonMap.toString()]);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: unn_mobile
22
description: A mobile application for UNN Portal website
33
publish_to: 'none'
44

5-
version: 0.5.6+382
5+
version: 0.5.6+383
66

77
environment:
88
sdk: '>=3.1.2 <4.0.0'

0 commit comments

Comments
 (0)