|
|
|
|
@ -1,38 +1,161 @@
|
|
|
|
|
import '../controllers/notification/firebase_notification_manger.dart';
|
|
|
|
|
import 'department.dart';
|
|
|
|
|
import 'enums/user_types.dart';
|
|
|
|
|
import 'hospital.dart';
|
|
|
|
|
|
|
|
|
|
class User {
|
|
|
|
|
String? clientId;
|
|
|
|
|
String? clientName;
|
|
|
|
|
int? departmentId;
|
|
|
|
|
String? departmentName;
|
|
|
|
|
String? message;
|
|
|
|
|
String? username;
|
|
|
|
|
String? userID;
|
|
|
|
|
String? email;
|
|
|
|
|
String? password;
|
|
|
|
|
String? token;
|
|
|
|
|
String? roles;
|
|
|
|
|
List<String>? userRoles;
|
|
|
|
|
String? tokenlife;
|
|
|
|
|
bool? isAuthenticated;
|
|
|
|
|
bool? hasError;
|
|
|
|
|
String? profilePhotoName;
|
|
|
|
|
String? id;
|
|
|
|
|
String userName;
|
|
|
|
|
String password;
|
|
|
|
|
String email;
|
|
|
|
|
String? image;
|
|
|
|
|
Hospital? hospital;
|
|
|
|
|
Department? department;
|
|
|
|
|
UsersTypes? type;
|
|
|
|
|
String? userName;
|
|
|
|
|
String? normalizedUserName;
|
|
|
|
|
String? normalizedEmail;
|
|
|
|
|
bool? emailConfirmed;
|
|
|
|
|
String? passwordHash;
|
|
|
|
|
String? securityStamp;
|
|
|
|
|
String? concurrencyStamp;
|
|
|
|
|
|
|
|
|
|
///I'm not sure from the datatype
|
|
|
|
|
String? phoneNumber;
|
|
|
|
|
String? whatsApp;
|
|
|
|
|
String? token;
|
|
|
|
|
bool isActive;
|
|
|
|
|
bool? phoneNumberConfirmed;
|
|
|
|
|
bool? twoFactorEnabled;
|
|
|
|
|
|
|
|
|
|
///I'm not sure from the datatype
|
|
|
|
|
String? lockoutEnd;
|
|
|
|
|
bool? lockoutEnabled;
|
|
|
|
|
int? accessFailedCount;
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
User({this.id, this.userName = "", this.email = "", this.password = "", this.phoneNumber, this.hospital, this.image, this.department, this.type, this.whatsApp, this.token, this.isActive = false});
|
|
|
|
|
User.fromJson(Map<String, 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 = <String>[];
|
|
|
|
|
json['userRoles'].forEach((v) {
|
|
|
|
|
userRoles!.add(v);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
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'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
|
final Map<String, dynamic> data = <String, dynamic>{};
|
|
|
|
|
data['client_id'] = clientId;
|
|
|
|
|
data['client_name'] = clientName;
|
|
|
|
|
data['department_id'] = departmentId;
|
|
|
|
|
data['department_name'] = departmentName;
|
|
|
|
|
data['message'] = message;
|
|
|
|
|
data['username'] = username;
|
|
|
|
|
data['userID'] = userID;
|
|
|
|
|
data['email'] = email;
|
|
|
|
|
data['password'] = password;
|
|
|
|
|
data['token'] = token;
|
|
|
|
|
data['roles'] = roles;
|
|
|
|
|
data['userRoles'] = userRoles;
|
|
|
|
|
data['tokenlife'] = tokenlife;
|
|
|
|
|
data['isAuthenticated'] = isAuthenticated;
|
|
|
|
|
data['hasError'] = hasError;
|
|
|
|
|
data['profilePhotoName'] = profilePhotoName;
|
|
|
|
|
data['id'] = id;
|
|
|
|
|
data['userName'] = userName;
|
|
|
|
|
data['normalizedUserName'] = normalizedUserName;
|
|
|
|
|
data['normalizedEmail'] = normalizedEmail;
|
|
|
|
|
data['emailConfirmed'] = emailConfirmed;
|
|
|
|
|
data['passwordHash'] = passwordHash;
|
|
|
|
|
data['securityStamp'] = securityStamp;
|
|
|
|
|
data['concurrencyStamp'] = concurrencyStamp;
|
|
|
|
|
data['phoneNumber'] = phoneNumber;
|
|
|
|
|
data['phoneNumberConfirmed'] = phoneNumberConfirmed;
|
|
|
|
|
data['twoFactorEnabled'] = twoFactorEnabled;
|
|
|
|
|
data['lockoutEnd'] = lockoutEnd;
|
|
|
|
|
data['lockoutEnabled'] = lockoutEnabled;
|
|
|
|
|
data['accessFailedCount'] = accessFailedCount;
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<Map<String, dynamic>> toLoginJson() async {
|
|
|
|
|
if (FirebaseNotificationManger.token == null) await FirebaseNotificationManger.getToken();
|
|
|
|
|
return {
|
|
|
|
|
"username": userName,
|
|
|
|
|
"pass": password,
|
|
|
|
|
"firebase_token": FirebaseNotificationManger.token ?? "",
|
|
|
|
|
"password": password,
|
|
|
|
|
"fireBaseToken": FirebaseNotificationManger.token ?? "",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toUpdateProfileJson() {
|
|
|
|
|
Map<String, dynamic> jsonObject = {};
|
|
|
|
|
if (department?.id != null && (department?.id?.isNotEmpty ?? false)) jsonObject["department"] = department?.id ?? "";
|
|
|
|
|
if (whatsApp != null && (whatsApp?.isNotEmpty ?? false)) jsonObject["whatsapp"] = whatsApp;
|
|
|
|
|
if (phoneNumber != null && (phoneNumber?.isNotEmpty ?? false)) jsonObject["phone"] = phoneNumber;
|
|
|
|
|
// if (department?.id != null && (department?.id?.isNotEmpty ?? false)) jsonObject["department"] = department?.id ?? "";
|
|
|
|
|
// if (whatsApp != null && (whatsApp?.isNotEmpty ?? false)) jsonObject["whatsapp"] = whatsApp;
|
|
|
|
|
// if (phoneNumber != null && (phoneNumber?.isNotEmpty ?? false)) jsonObject["phoneNumber"] = phoneNumber;
|
|
|
|
|
return jsonObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -41,59 +164,12 @@ class User {
|
|
|
|
|
return {
|
|
|
|
|
"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 {
|
|
|
|
|
"uid": id,
|
|
|
|
|
"name": userName,
|
|
|
|
|
"email": email,
|
|
|
|
|
"token": token,
|
|
|
|
|
"phone": phoneNumber,
|
|
|
|
|
"whatsapp": whatsApp,
|
|
|
|
|
"client": hospital?.id,
|
|
|
|
|
"client_name": hospital?.name,
|
|
|
|
|
"department": department?.id,
|
|
|
|
|
"department_name": department?.name,
|
|
|
|
|
// "whatsapp": whatsApp,
|
|
|
|
|
// "client": hospital?.id,
|
|
|
|
|
// "department": department?.id,
|
|
|
|
|
"phoneNumber": phoneNumber,
|
|
|
|
|
"password": password,
|
|
|
|
|
"picture": image,
|
|
|
|
|
"active": isActive ? 1 : 0,
|
|
|
|
|
"role": type == UsersTypes.engineer ? "field_engineer" : "normal_user",
|
|
|
|
|
// "token":token, pass is token
|
|
|
|
|
"fireBaseToken": FirebaseNotificationManger.token ?? "",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
factory User.fromJson(Map<String, dynamic> parsedJson) {
|
|
|
|
|
UsersTypes type;
|
|
|
|
|
switch (parsedJson["role"]) {
|
|
|
|
|
case "field_engineer":
|
|
|
|
|
type = UsersTypes.engineer;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
type = UsersTypes.normal_user;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return User(
|
|
|
|
|
id: parsedJson["uid"],
|
|
|
|
|
userName: parsedJson["name"] ?? parsedJson["title"],
|
|
|
|
|
email: parsedJson["mail"] ?? parsedJson["email"],
|
|
|
|
|
hospital: Hospital(id: parsedJson["client"], name: parsedJson["client_name"]),
|
|
|
|
|
department: Department(
|
|
|
|
|
id: parsedJson["department"],
|
|
|
|
|
name: parsedJson["department_name"],
|
|
|
|
|
),
|
|
|
|
|
image: parsedJson["picture"],
|
|
|
|
|
phoneNumber: parsedJson["phone"],
|
|
|
|
|
whatsApp: parsedJson["whatsapp"],
|
|
|
|
|
token: parsedJson["token"],
|
|
|
|
|
isActive: parsedJson["active"] == "1",
|
|
|
|
|
type: type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|