parent
a219d81ccc
commit
d0f083ce22
@ -1,108 +1,219 @@
|
||||
import 'package:test_sa/controllers/notification/firebase_notification_manger.dart';
|
||||
import 'package:test_sa/models/department.dart';
|
||||
import 'package:test_sa/models/enums/user_types.dart';
|
||||
import 'package:test_sa/models/hospital.dart';
|
||||
|
||||
class User {
|
||||
int clientId;
|
||||
String clientName;
|
||||
int departmentId;
|
||||
String departmentName;
|
||||
String message;
|
||||
String username;
|
||||
String userID;
|
||||
String email;
|
||||
String password;
|
||||
String token;
|
||||
dynamic roles;
|
||||
List<UserRoles> userRoles;
|
||||
String tokenlife;
|
||||
bool isAuthenticated;
|
||||
bool hasError;
|
||||
String profilePhotoName;
|
||||
String id;
|
||||
String userName;
|
||||
String password;
|
||||
String email;
|
||||
Hospital hospital;
|
||||
Department department;
|
||||
UsersTypes type;
|
||||
String normalizedUserName;
|
||||
String normalizedEmail;
|
||||
bool emailConfirmed;
|
||||
dynamic passwordHash;
|
||||
String securityStamp;
|
||||
String concurrencyStamp;
|
||||
String phoneNumber;
|
||||
String whatsApp;
|
||||
String token;
|
||||
bool isActive;
|
||||
DateTime tokenLife;
|
||||
bool phoneNumberConfirmed;
|
||||
bool twoFactorEnabled;
|
||||
dynamic lockoutEnd;
|
||||
bool lockoutEnabled;
|
||||
int accessFailedCount;
|
||||
|
||||
User(
|
||||
{this.id,
|
||||
this.userName = "",
|
||||
this.email = "",
|
||||
this.password = "",
|
||||
this.phoneNumber = "",
|
||||
this.hospital,
|
||||
this.department,
|
||||
this.type,
|
||||
this.whatsApp,
|
||||
this.token,
|
||||
this.tokenLife,
|
||||
this.isActive = false});
|
||||
User({
|
||||
this.clientId,
|
||||
this.clientName,
|
||||
this.departmentId,
|
||||
this.departmentName,
|
||||
this.message,
|
||||
this.username,
|
||||
this.userID,
|
||||
this.email,
|
||||
this.password,
|
||||
this.token,
|
||||
this.roles,
|
||||
this.userRoles,
|
||||
this.tokenlife,
|
||||
this.isAuthenticated,
|
||||
this.hasError,
|
||||
this.profilePhotoName,
|
||||
this.id,
|
||||
this.userName,
|
||||
this.normalizedUserName,
|
||||
this.normalizedEmail,
|
||||
this.emailConfirmed,
|
||||
this.passwordHash,
|
||||
this.securityStamp,
|
||||
this.concurrencyStamp,
|
||||
this.phoneNumber,
|
||||
this.phoneNumberConfirmed,
|
||||
this.twoFactorEnabled,
|
||||
this.lockoutEnd,
|
||||
this.lockoutEnabled,
|
||||
this.accessFailedCount,
|
||||
});
|
||||
|
||||
Future<Map<String, dynamic>> toLoginJson() async {
|
||||
if (FirebaseNotificationManger.token == null) await FirebaseNotificationManger.getToken();
|
||||
return {
|
||||
"username": userName,
|
||||
"password": password,
|
||||
"firebase_token": FirebaseNotificationManger?.token ?? "",
|
||||
"fireBaseToken": FirebaseNotificationManger?.token ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
UsersTypes get type {
|
||||
switch (userRoles.first.name) {
|
||||
case "Engineer":
|
||||
return UsersTypes.engineer;
|
||||
case "Nurse":
|
||||
return UsersTypes.normal_user;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toUpdateProfileJson() {
|
||||
Map<String, dynamic> jsonObject = {};
|
||||
if (department?.id != null) jsonObject["department"] = department.id;
|
||||
if (whatsApp != null && whatsApp.isNotEmpty) jsonObject["whatsapp"] = whatsApp;
|
||||
if (phoneNumber != null && phoneNumber.isNotEmpty) jsonObject["phone"] = phoneNumber;
|
||||
// if (departmentId != null) jsonObject["department"] = departmentId;
|
||||
// if (whatsApp != null && whatsApp.isNotEmpty) jsonObject["whatsapp"] = whatsApp;
|
||||
// if (phoneNumber != null && phoneNumber.isNotEmpty) jsonObject["phone"] = phoneNumber;
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> toRegisterJson() async {
|
||||
if (FirebaseNotificationManger.token == null) await FirebaseNotificationManger.getToken();
|
||||
// if (FirebaseNotificationManger.token == null) await FirebaseNotificationManger.getToken();
|
||||
return {
|
||||
"username": userName,
|
||||
"email": email,
|
||||
"whatsapp": whatsApp,
|
||||
"client": hospital.id,
|
||||
"department": department?.id,
|
||||
"phone": phoneNumber,
|
||||
"pass": password,
|
||||
"firebase_token": FirebaseNotificationManger?.token ?? "",
|
||||
// "username": userName,
|
||||
// "email": email,
|
||||
// "whatsapp": whatsApp,
|
||||
// "client": hospital.id,
|
||||
// "department": department?.id,
|
||||
// "phone": phoneNumber,
|
||||
// "pass": password,
|
||||
// "firebase_token": FirebaseNotificationManger?.token ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"userID": id,
|
||||
"username": userName,
|
||||
"email": email,
|
||||
"token": token,
|
||||
"phoneNumber": phoneNumber,
|
||||
"whatsapp": whatsApp,
|
||||
"client_id": hospital?.id,
|
||||
"client_name": hospital?.name,
|
||||
"department_id": department?.id,
|
||||
"department_name": department?.name,
|
||||
//"password":password,
|
||||
"tokenlife": tokenLife.toIso8601String(),
|
||||
"active": isActive,
|
||||
"userRoles": type == UsersTypes.engineer ? "value: R-6" : "value: R-5",
|
||||
// "token":token, pass is token
|
||||
};
|
||||
final map = <String, dynamic>{};
|
||||
map['client_id'] = clientId;
|
||||
map['client_name'] = clientName;
|
||||
map['department_id'] = departmentId;
|
||||
map['department_name'] = departmentName;
|
||||
map['message'] = message;
|
||||
map['username'] = username;
|
||||
map['userID'] = userID;
|
||||
map['email'] = email;
|
||||
map['password'] = password;
|
||||
map['token'] = token;
|
||||
map['roles'] = roles;
|
||||
if (userRoles != null) {
|
||||
map['userRoles'] = userRoles.map((v) => v.toJson()).toList();
|
||||
}
|
||||
map['tokenlife'] = tokenlife;
|
||||
map['isAuthenticated'] = isAuthenticated;
|
||||
map['hasError'] = hasError;
|
||||
map['profilePhotoName'] = profilePhotoName;
|
||||
map['id'] = id;
|
||||
map['userName'] = userName;
|
||||
map['normalizedUserName'] = normalizedUserName;
|
||||
map['normalizedEmail'] = normalizedEmail;
|
||||
map['emailConfirmed'] = emailConfirmed;
|
||||
map['passwordHash'] = passwordHash;
|
||||
map['securityStamp'] = securityStamp;
|
||||
map['concurrencyStamp'] = concurrencyStamp;
|
||||
map['phoneNumber'] = phoneNumber;
|
||||
map['phoneNumberConfirmed'] = phoneNumberConfirmed;
|
||||
map['twoFactorEnabled'] = twoFactorEnabled;
|
||||
map['lockoutEnd'] = lockoutEnd;
|
||||
map['lockoutEnabled'] = lockoutEnabled;
|
||||
map['accessFailedCount'] = accessFailedCount;
|
||||
return map;
|
||||
}
|
||||
|
||||
factory User.fromJson(Map<String, dynamic> parsedJson) {
|
||||
UsersTypes type;
|
||||
if (parsedJson["userRoles"].toString().contains("value: R-4") || parsedJson["userRoles"].toString().contains("value: R-5") || parsedJson["userRoles"].toString().contains("value: R-7")) {
|
||||
type = UsersTypes.normal_user;
|
||||
} else {
|
||||
type = UsersTypes.engineer;
|
||||
User.fromJson(dynamic json) {
|
||||
clientId = json['client_id'];
|
||||
clientName = json['client_name'];
|
||||
departmentId = json['department_id'];
|
||||
departmentName = json['department_name'];
|
||||
message = json['message'];
|
||||
username = json['username'];
|
||||
userID = json['userID'];
|
||||
email = json['email'];
|
||||
password = json['password'];
|
||||
token = json['token'];
|
||||
roles = json['roles'];
|
||||
if (json['userRoles'] != null) {
|
||||
userRoles = [];
|
||||
json['userRoles'].forEach((v) {
|
||||
userRoles.add(UserRoles.fromJson(v));
|
||||
});
|
||||
}
|
||||
return User(
|
||||
id: parsedJson["userID"],
|
||||
userName: parsedJson["username"],
|
||||
email: parsedJson["email"],
|
||||
hospital: Hospital(id: parsedJson["client_id"], name: parsedJson["client_name"]),
|
||||
department: Department(
|
||||
id: parsedJson["department_id"],
|
||||
name: parsedJson["department_name"],
|
||||
),
|
||||
phoneNumber: parsedJson["phoneNumber"],
|
||||
whatsApp: parsedJson["phoneNumber"],
|
||||
token: parsedJson["token"],
|
||||
isActive: parsedJson["isAuthenticated"],
|
||||
tokenLife: DateTime.tryParse(parsedJson["tokenlife"] ?? ""),
|
||||
type: type);
|
||||
tokenlife = json['tokenlife'];
|
||||
isAuthenticated = json['isAuthenticated'];
|
||||
hasError = json['hasError'];
|
||||
profilePhotoName = json['profilePhotoName'];
|
||||
id = json['id'];
|
||||
userName = json['userName'];
|
||||
normalizedUserName = json['normalizedUserName'];
|
||||
normalizedEmail = json['normalizedEmail'];
|
||||
emailConfirmed = json['emailConfirmed'];
|
||||
passwordHash = json['passwordHash'];
|
||||
securityStamp = json['securityStamp'];
|
||||
concurrencyStamp = json['concurrencyStamp'];
|
||||
phoneNumber = json['phoneNumber'];
|
||||
phoneNumberConfirmed = json['phoneNumberConfirmed'];
|
||||
twoFactorEnabled = json['twoFactorEnabled'];
|
||||
lockoutEnd = json['lockoutEnd'];
|
||||
lockoutEnabled = json['lockoutEnabled'];
|
||||
accessFailedCount = json['accessFailedCount'];
|
||||
}
|
||||
}
|
||||
|
||||
class UserRoles {
|
||||
UserRoles({
|
||||
this.id,
|
||||
this.name,
|
||||
this.value,
|
||||
});
|
||||
|
||||
UserRoles.fromJson(dynamic json) {
|
||||
id = json['id'];
|
||||
name = json['name'];
|
||||
value = json['value'];
|
||||
}
|
||||
String id;
|
||||
String name;
|
||||
String value;
|
||||
UserRoles copyWith({
|
||||
String id,
|
||||
String name,
|
||||
String value,
|
||||
}) =>
|
||||
UserRoles(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
value: value ?? this.value,
|
||||
);
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map['id'] = id;
|
||||
map['name'] = name;
|
||||
map['value'] = value;
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue