OpenContacts/lib/models/users/user.dart

44 lines
1 KiB
Dart
Raw Normal View History

import 'package:recon/models/users/contact_status.dart';
import 'package:recon/models/users/user_profile.dart';
2023-04-30 09:43:59 -04:00
class User {
final String id;
final String username;
final DateTime registrationDate;
final UserProfile? userProfile;
const User({required this.id, required this.username, required this.registrationDate, this.userProfile});
factory User.fromMap(Map map) {
UserProfile? profile;
try {
profile = UserProfile.fromMap(map["profile"]);
} catch (e) {
profile = null;
}
return User(
id: map["id"],
username: map["username"],
registrationDate: DateTime.parse(map["registrationDate"]),
userProfile: profile,
);
}
2023-04-30 17:14:29 -04:00
Map toMap() {
return {
"id": id,
"username": username,
"registrationDate": registrationDate.toIso8601String(),
"profile": userProfile?.toMap(),
};
}
Map asContactRequest(String ownerId) {
return {
"ownerId": ownerId,
"id": id,
"contactUsername": username,
"contactStatus": ContactStatus.accepted.name,
};
}
2023-04-30 09:43:59 -04:00
}